AdRotator.ImageKey 属性

定义

返回广告中的从中检索图像 URL 的元素名。Returns the element name from which the image URL is retrieved from an advertisement. 默认值为“ImageUrl”。The default value is "ImageUrl". 此 API 已废弃不用。This API is obsolete. 若要了解如何开发 ASP.NET 移动应用,请参阅 Mobile Apps & Sites with ASP.NET (ASP.NET 移动应用和网站)。For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET. 此 API 已废弃不用。This API is obsolete. 若要了解如何开发 ASP.NET 移动应用,请参阅 Mobile Apps & Sites with ASP.NET (ASP.NET 移动应用和网站)。For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET.

public:
 property System::String ^ ImageKey { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
public string ImageKey { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.ImageKey : string with get, set
Public Property ImageKey As String

属性值

String

从中为广告检索图像 URL 的元素名。The element name from which the image URL is retrieved for an advertisement.

属性

示例

下面的代码示例演示如何使用 ImageKey 属性从 XML 文件中的记录中选择特定项。The following code example demonstrates how to use the ImageKey property to select a specific item from a record in the XML file. 此 .aspx 文件指定可以从 XML 文件的元素中获取图像 URL 的值 <MobileImageSrc><Choice> 如果用户的浏览器需要 WML 标记,则使用元素选择不同的图像 url。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.

.aspx 文件:The .aspx file:

<%@ 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>
<%@ Page Language="VB" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" %>
<%@ Import Namespace="System.Web.Mobile" %>

<script runat="server">
    '<Snippet3>
    Private Sub AdCreated_Event(ByVal sender As Object, _
        ByVal e As AdCreatedEventArgs)
        
        Label2.Text = "Clicking the AdRotator control takes you to " + _
            e.NavigateUrl
    End Sub
    '</Snippet3>

    ' Determine whether the current browser is a WML brower.
    Public Function isWml11(ByVal caps As MobileCapabilities, _
        ByVal value As String) As Boolean
        If Not caps.Crawler AndAlso caps.PreferredRenderingMime = _
            MobileCapabilities.PreferredRenderingTypeWml11 Then
            
            Return True
        Else
            Return False
        End If
    End Function
</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>

(的示例 ads.xml 文件必须位于 App_Data 文件夹中) :The sample ads.xml file (which must be located in the App_Data folder):

<?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>

注解

可以出于各种目的在源 XML 文件中创建元素。You can create elements in the source XML file for a variety of purposes. 例如,你可能想要对移动页和网页使用相同的 XML 文件,但每个文件都要有不同的映像文件。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. 使用 ImageKey 属性指定要用于图像 URL 的 XML 文件中的元素。Use the ImageKey property to specify which element in your XML file you want to use for the image URL.

你还可以使用单独 <Choice> 的元素来覆盖此设置,以显示播发的替代图像。You can also use separate <Choice> elements to override this setting to show alternate images for the advertisement.

适用于

另请参阅