Edit

Share via


AdRotator.ImageKey Property

Definition

Returns the element name from which the image URL is retrieved from an advertisement. The default value is "ImageUrl". This API is obsolete. For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET. This API is obsolete. For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET.

C#
[System.ComponentModel.Bindable(true)]
public string ImageKey { get; set; }

Property Value

The element name from which the image URL is retrieved for an advertisement.

Attributes

Examples

The following code example demonstrates how to use the ImageKey property to select a specific item from a record in the XML file. This .aspx file specifies that the value for the image URL can be obtained from the <MobileImageSrc> element of the XML file, and uses a <Choice> element to select a different image URL if the user's browser requires WML markup.

The .aspx file:

ASP.NET (C#)
<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" %>
<%@ Import Namespace="System.Web.Mobile" %>

<script runat="server">
    //<Snippet3>
    private void AdCreated_Event(Object sender, AdCreatedEventArgs e)
    {
       Label2.Text = "Clicking the AdRotator control takes you to " + 
           e.NavigateUrl;
    }
    //</Snippet3>

    // Determine whether the current browser is a WML brower
    public bool isWML11(MobileCapabilities caps, string optValue)
    {
        // Determine if the browser is not a Web crawler and 
        // requires WML markup
        if (!caps.Crawler && caps.PreferredRenderingType == 
            MobileCapabilities.PreferredRenderingTypeWml11)
            return true;
        else
            return false;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="form1" runat="server">
        <!-- The AdRotator control -->
        <mobile:AdRotator id="AdControl" runat="server"
            ImageKey="MobileImgSrc" NavigateUrlKey="TargetUrl"
            AdvertisementFile="App_Data/ads.xml" Alignment="Left" 
            KeywordFilter="Developer" OnAdCreated="AdCreated_Event">
            <DeviceSpecific>
                <Choice Filter="isWML11" NavigateUrlKey="WmlTargetUrl" 
                    ImageKey= "WmlImageSrc" />
            </DeviceSpecific>
        </mobile:AdRotator>
        
        <!-- The instructions label -->
        <mobile:Label id="Label1" runat="server" 
            Text="Refresh the page to change the advertisement" />

        <!-- The URL info label -->
        <mobile:Label id="Label2" runat="server" />
    </mobile:form>
</body>
</html>

The sample ads.xml file (which must be located in the App_Data folder):

XML
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
  <Ad>
    <WebImgSrc>imgA1.gif</WebImgSrc>
    <MobileImgSrc>imgA2.gif</MobileImgSrc>
    <WmlImgSrc>imgA3.gif</WmlImgSrc>
    <TargetUrl>http://msdn.microsoft.com/</TargetUrl>
    <WmlTargetUrl>http://OurServer/MS-MSDN.wml</WmlTargetUrl>
    <AlternateText>MSDN</AlternateText>
    <Keyword>Developer</Keyword>
    <Impressions>80</Impressions>
  </Ad>
  <Ad>
    <WebImgSrc>imgB1.gif</WebImgSrc>
    <MobileImgSrc>imgB2.gif</MobileImgSrc>
    <WmlImgSrc>imgB3.gif</WmlImgSrc>
    <TargetUrl>http://www.microsoft.com/</TargetUrl>
    <WmlTargetUrl>http://OurServer/MS-Home.wml</WmlTargetUrl>
    <AlternateText>Microsoft</AlternateText>
    <Keyword>Customer</Keyword>
    <Impressions>90</Impressions>
  </Ad>
  <Ad>
    <WebImgSrc>imgC1.gif</WebImgSrc>
    <MobileImgSrc>imgC2.gif</MobileImgSrc>
    <WmlImgSrc>imgC3.gif</WmlImgSrc>
    <TargetUrl>http://www.microsoft.com/net/</TargetUrl>
    <WmlTargetUrl>http://OurServer/MS-Net.wml</WmlTargetUrl>
    <AlternateText>.NET</AlternateText>
    <Keyword>Developer</Keyword>
    <Impressions>80</Impressions>
  </Ad>
</Advertisements>

Remarks

You can create elements in the source XML file for a variety of purposes. For example, you may want to use the same XML file for both mobile pages and Web pages, but want a different image file for each one. Use the ImageKey property to specify which element in your XML file you want to use for the image URL.

You can also use separate <Choice> elements to override this setting to show alternate images for the advertisement.

Applies to

Product Versions
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also