次の方法で共有


AdRotator.AdCreated イベント

作成されたコントロールがぺージ上に表示されるまでの間、サーバーへのラウンド トリップごとに 1 回発生します。

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

構文

'宣言
Public Event AdCreated As AdCreatedEventHandler
'使用
Dim instance As AdRotator
Dim handler As AdCreatedEventHandler

AddHandler instance.AdCreated, handler
public event AdCreatedEventHandler AdCreated
public:
event AdCreatedEventHandler^ AdCreated {
    void add (AdCreatedEventHandler^ value);
    void remove (AdCreatedEventHandler^ value);
}
/** @event */
public void add_AdCreated (AdCreatedEventHandler value)

/** @event */
public void remove_AdCreated (AdCreatedEventHandler value)
JScript では、このクラスで定義されているイベントを処理できます。ただし、独自のイベントは定義できません。
適用できません。

解説

このイベントは、作成されたコントロールがページ上に表示されるまでの間、サーバーへのラウンド トリップごとに 1 回発生します。AdvertisementFile プロパティが設定されている場合、このイベントは広告がファイルから選択された後で発生します。

AdCreated イベントのイベント ハンドラに渡された引数を変更することにより、AdRotator コントロールがどのように表示されるかを制御できます。AdvertisementFile プロパティが設定されていない場合は、別の広告ファイルを使用せずに、広告情報を直接指定できます。AdvertisementFile プロパティが設定されている場合は、別のページへのリダイレクトなど、AdRotator コントロールの動作を拡張できます。

メモメモ :

ページ キャッシュが有効な場合、AdRotator コントロールはキャッシュされません。Web ページが更新されるたびに、新しい広告が選択されます。ただし、AdCreated イベントのイベント ハンドラが提供されている場合は、新しい広告は選択されません。

イベント処理の詳細については、「イベントの処理と発生」を参照してください。

トピック 場所
方法 : AdRotator Web サーバー コントロールでプログラムによって広告を選択する Visual Studio ASP .NET での Web アプリケーションの作成
方法 : AdRotator Web サーバー コントロールでプログラムによって広告を選択する Visual Studio ASP .NET での Web アプリケーションの作成
方法 : AdRotator Web サーバー コントロールでプログラムによって広告を選択する ASP .NET Web アプリケーションの作成

使用例

AdCreated イベントのハンドラを指定およびコーディングする方法を次のコード例に示します。この例では、AdRotator コントロールが作成されたときに広告に関連付けられた URL を取得して、次にその URL を表示します。

メモメモ :

次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。

<%@ 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.href
       End Sub
    </script>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>AdRotator Example</h3>
 
       <asp:AdRotator id="test1" runat="server"
            AdvertisementFile = "~/App_Data/Ads.xml"
            Borderwidth="1"
            Target="_blank"
            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=e.href;   
       }      
    </script>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>AdRotator Example</h3>
 
       <asp:AdRotator id="test1" runat="server"
            AdvertisementFile = "~/App_Data/Ads.xml"
            Borderwidth="1"
            Target="_blank"
            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=e.href;   
       }      
    </script>
 
 <body>
 
    <form id="form1" runat="server">
 
       <h3>AdRotator Example</h3>
 
       <asp:AdRotator id="test1" runat="server"
            AdvertisementFile = "~/App_Data/Ads.xml"
            Borderwidth="1"
            Target="_blank"
            OnAdCreated="AdCreated_Event"/><br /><br />
 
       <asp:label id="Message" runat="server"/>
 
    </form>
 
 </body>
 </html>
    

広告情報を含む XML ファイルの書式を設定する方法を次のコード例に示します。XML ファイルの詳細については、AdvertisementFile プロパティのトピックを参照してください。

<Advertisements>
  <Ad>
    <ImageUrl>~/Images/image1.jpg</ImageUrl>
    <Height>60</Height>
    <Width>190</Width>
    <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>~/Images/image2.jpg</ImageUrl>
    <Height>90</Height>
    <Width>90</Width>
    <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>
メモメモ :

次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。

<%@ 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 AdCreated Example</title>
</head>
 
   <script runat="server">

      Sub Page_Load(sender As Object, e As EventArgs)

         ' Create an EventHandler delegate for the method you want to handle the event
         ' and then add it to the list of methods called when the event is raised.
         AddHandler Ad.AdCreated, AddressOf AdCreated_Event

      End Sub

      Sub AdCreated_Event(sender As Object, e As AdCreatedEventArgs) 

         ' Override the AlternateText value from the ads.xml file.
         e.AlternateText = "Visit this site!"   

      End Sub      

   </script>
 
<body>
 
   <form id="form1" runat="server">
 
      <h3>AdRotator AdCreated Example</h3>

      Notice that the AlternateText property of the advertisement <br />
      has been programmatically modified from the value in the XML <br />
      file. 

      <br /><br />
 
      <asp:AdRotator id="Ad" runat="server"
           AdvertisementFile = "~/App_Data/Ads.xml"
           Borderwidth="1"
           Target="_blank"/>
 
   </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 AdCreated Example</title>
</head>
 
   <script runat="server">

      void Page_Load(Object sender, EventArgs e)
      {

         // Create an EventHandler delegate for the method you want to handle the event
         // and then add it to the list of methods called when the event is raised.
         Ad.AdCreated += new System.Web.UI.WebControls.AdCreatedEventHandler(this.AdCreated_Event);

      }

      void AdCreated_Event(Object sender, AdCreatedEventArgs e) 
      {

         // Override the AlternateText value from the ads.xml file.
         e.AlternateText = "Visit this site!";   

      }      

   </script>
 
<body>
 
   <form id="form1" runat="server">
 
      <h3>AdRotator AdCreated Example</h3>

      Notice that the AlternateText property of the advertisement <br />
      has been programmatically modified from the value in the XML <br />
      file. 

      <br /><br />
 
      <asp:AdRotator id="Ad" runat="server"
           AdvertisementFile = "~/App_Data/Ads.xml"
           Borderwidth="1"
           Target="_blank"/>
 
   </form>
 
</body>
</html>

プラットフォーム

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

参照

関連項目

AdRotator クラス
AdRotator メンバ
System.Web.UI.WebControls 名前空間
OnAdCreated
AdCreatedEventHandler デリゲート
AdCreatedEventArgs

その他の技術情報

AdRotator Web サーバー コントロール