AdCreatedEventArgs.AdProperties 屬性

定義

取得 IDictionary 物件,包含目前所顯示廣告的所有廣告屬性。

public:
 property System::Collections::IDictionary ^ AdProperties { System::Collections::IDictionary ^ get(); };
public System.Collections.IDictionary AdProperties { get; }
member this.AdProperties : System.Collections.IDictionary
Public ReadOnly Property AdProperties As IDictionary

屬性值

IDictionary,包含目前所顯示廣告的廣告屬性清單。 預設值是 Empty

範例

下列程式碼範例示範如何使用 AdProperties 事件處理常式中的 OnAdCreated 屬性來提供自訂標題。

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
    <title>AdRotator Example</title>
</head>
 
    <script language="c#" runat="server">
       void AdCreated_Event(Object sender, AdCreatedEventArgs e) 
       {
          Message.Text=(string)e.AdProperties["Caption"];
       }      
    </script>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>AdRotator Example</h3>
 
       <asp:AdRotator id="test1" runat="server"
            AdvertisementFile = "Ads.xml"
        Borderwidth="1"
            Target="_newwwindow"
            OnAdCreated="AdCreated_Event"/><br /><br />
 
       <asp:label id="Message" runat="server"/>
 
    </form>
 
 </body>
 </html>
<%@ Page Language="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
    <title>AdRotator Example</title>
</head>
 
    <script language="vb" runat="server">
       Sub AdCreated_Event(sender As Object, e As AdCreatedEventArgs) 
          Message.Text = e.AdProperties("Caption")
       End Sub     
    </script>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>AdRotator Example</h3>
 
       <asp:AdRotator id="test1" runat="server"
            AdvertisementFile = "Ads.xml"
        Borderwidth="1"
            Target="_newwwindow"
            OnAdCreated="AdCreated_Event"/><br /><br />
 
       <asp:label id="Message" runat="server"/>
 
    </form>
 
 </body>
 </html>

<Advertisements>
 
     <Ad>
         <ImageUrl>image1.jpg</ImageUrl>
         <NavigateUrl>http://www.microsoft.com</NavigateUrl>
         <AlternateText>Microsoft Main Site</AlternateText>
         <Impressions>80</Impressions>
         <Keyword>Topic1</Keyword>
         <Caption>This is the caption for Ad#1</Caption>          
     </Ad>
 
     <Ad>
         <ImageUrl>image2.jpg</ImageUrl>
         <NavigateUrl>http://www.wingtiptoys.com</NavigateUrl>
         <AlternateText>Wing Tip Toys</AlternateText>
         <Impressions>80</Impressions>
         <Keyword>Topic2</Keyword>
         <Caption>This is the caption for Ad#2</Caption>                
     </Ad>
 
 </Advertisements>

下列程式碼範例示範如何在廣告 XML 檔案中包含有關公告的自訂屬性。 如需 XML 檔案的詳細資訊,請參閱 AdvertisementFile 類別的 AdRotator 屬性。

<Advertisements>  
 <Ad>  
 <ImageUrl>image1.jpg</ImageUrl>  
 <NavigateUrl>http://www.microsoft.com</NavigateUrl>  
 <AlternateText>Microsoft Main Site</AlternateText>  
 <Impressions>80</Impressions>  
 <Keyword>Topic1</Keyword>  
 <Caption>This is the caption for Ad#1</Caption>   
 </Ad>  
 <Ad>  
 <ImageUrl>image2.jpg</ImageUrl>  
 <NavigateUrl>http://www.wingtiptoys.com</NavigateUrl>  
 <AlternateText>Wingtip Toys</AlternateText>  
 <Impressions>80</Impressions>  
 <Keyword>Topic2</Keyword>  
 <Caption>This is the caption for Ad#2</Caption>   
 </Ad>  
</Advertisements>  

備註

AdProperties使用 屬性可取得 System.Collections.IDictionary 物件,其中包含目前顯示之廣告的廣告屬性。 物件的索引鍵和值 System.Collections.IDictionary 屬於 類型 System.String

每次 AdRotator 控制項顯示在網頁上時,控制項都會隨機選取廣告。 所選公告的屬性會從廣告 XML 檔案中擷取,並儲存在 物件中 System.Collections.IDictionary 。 當 AdRotator 控制項建立 類別的新實例 AdCreatedEventArgs 時, AdProperties 屬性會以 System.Collections.IDictionary 物件初始化。

廣告的相關自訂屬性,例如廣告標題,也可以包含在廣告 XML 檔案中。 在事件處理常式中使用 OnAdCreated 這個屬性來取得自訂屬性。

適用於

另請參閱