次の方法で共有


AdCreatedEventArgs.AdProperties プロパティ

現在表示されている広告のすべての広告プロパティが格納されている System.Collections.IDictionary オブジェクトを取得します。

名前空間: System.Web.UI.WebControls
アセンブリ: System.Web (system.web.dll 内)

構文

'宣言
Public ReadOnly Property AdProperties As IDictionary
'使用
Dim instance As AdCreatedEventArgs
Dim value As IDictionary

value = instance.AdProperties
public IDictionary AdProperties { get; }
public:
property IDictionary^ AdProperties {
    IDictionary^ get ();
}
/** @property */
public IDictionary get_AdProperties ()
public function get AdProperties () : IDictionary
適用できません。

プロパティ値

現在表示されている広告の広告プロパティのリストが格納されている System.Collections.IDictionary。既定値は String.Empty です。

解説

AdProperties プロパティを使用して、現在表示されている広告の広告プロパティが格納されている System.Collections.IDictionary オブジェクトを取得します。System.Collections.IDictionary オブジェクトのキーと値は、System.String 型です。

AdRotator コントロールは、コントロールが Web ページに表示されるたび、ランダムに広告を選択します。選択した広告の属性は広告 XML ファイルから抽出され、System.Collections.IDictionary オブジェクトに格納されます。AdRotator コントロールが AdCreatedEventArgs クラスの新しいインスタンスを作成すると、AdProperties プロパティは System.Collections.IDictionary オブジェクトを使用して初期化されます。

広告キャプションなど、広告のカスタム属性も広告 XML ファイルに含めることができます。カスタム属性を取得するには、OnAdCreated イベント ハンドラのプロパティを使用します。

使用例

OnAdCreated イベント ハンドラの AdProperties プロパティを使用して、カスタム キャプションを作成する方法を次のコード例に示します。

<%@ 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>
<%@ 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="JScript" 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="jscript" runat="server">
       function AdCreated_Event(sender, e : AdCreatedEventArgs) 
       {
          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>
<Advertisements>
 
     <Ad>
         <ImageUrl>image1.jpg</ImageUrl>
         <href>https://www.microsoft.com</href>
         <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>
         <href>http://www.wingtiptoys.com</href>
         <AlternateText>Wing Tip Toys</AlternateText>
         <Impressions>80</Impressions>
         <Keyword>Topic2</Keyword>
         <Caption>This is the caption for Ad#2</Caption>                
     </Ad>
 
 </Advertisements>

広告のカスタム属性を広告 XML ファイルに含める方法を次のコード例に示します。XML ファイルの詳細については、AdRotator クラスの AdvertisementFile プロパティのトピックを参照してください。

 <Advertisements>
  <Ad>
  <ImageUrl>image1.jpg</ImageUrl>
  <href>https://www.microsoft.com</href>
  <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>
  <href>http://www.wingtiptoys.com</href>
  <AlternateText>Wingtip Toys</AlternateText>
  <Impressions>80</Impressions>
  <Keyword>Topic2</Keyword>
  <Caption>This is the caption for Ad#2</Caption> 
  </Ad>
 </Advertisements>

プラットフォーム

Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition

Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。

バージョン情報

.NET Framework

サポート対象 : 3.0,2.0,1.1,1.0

参照

関連項目

AdCreatedEventArgs クラス
AdCreatedEventArgs メンバ
System.Web.UI.WebControls 名前空間
AdRotator.AdvertisementFile
OnAdCreated
System.Collections.IDictionary
String.Empty