次の方法で共有


AdRotator.OnAdCreated メソッド

AdRotator コントロールの AdCreated イベントを発生させます。

Protected Overridable Sub OnAdCreated( _
   ByVal e As AdCreatedEventArgs _)
[C#]
protected virtual void OnAdCreated(AdCreatedEventArgse);
[C++]
protected: virtual void OnAdCreated(AdCreatedEventArgs* e);
[JScript]
protected function OnAdCreated(
   e : AdCreatedEventArgs);

パラメータ

解説

AdCreated イベントは、作成された AdRotator コントロールがページ上に表示されるまでの間、サーバー上で発生します。 AdvertisementFile プロパティが設定されている場合は、広告が AdRotator コントロールによって選択された後、 AdCreated イベントが発生します。

イベントが発生すると、デリゲートを使用してイベント処理メソッドが呼び出されます。詳細については、「 イベントの発生 」を参照してください。

継承時の注意: 派生クラスで OnAdCreated をオーバーライドする場合は、基本クラスの OnAdCreated メソッドを呼び出してください。

使用例

[Visual Basic, C#, JScript] AdCreated イベントのハンドラを指定およびコード化する方法を次の例に示します。この例では、 AdRotator コントロールが作成されたときに広告に関連付けられた URL を取得して、次にその URL を表示します。2 番目の例では、リストされたコードを格納している Ads.xml という XML ファイルを作成する必要があります。Ads.xml ファイルはこの例のソース ファイルと同じディレクトリにある必要があります。

 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
 <head>
 
 </head>
 
    <script language="VB" runat="server">
       Sub AdCreated_Event(sender As Object, e As AdCreatedEventArgs) 
          Message.Text=e.href
       End Sub
    </script>
 
 <body>
 
    <form 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>
    

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

<html>
 <head>
 
 </head>
 
    <script language="C#" runat="server">
       void AdCreated_Event(Object sender, AdCreatedEventArgs e) 
       {
          Message.Text=e.href;   
       }      
    </script>
 
 <body>
 
    <form 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>
    

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
 <head>
 
 </head>
 
    <script language="JScript" runat="server">
       function AdCreated_Event(sender, e : AdCreatedEventArgs) 
       {
          Message.Text=e.href;   
       }      
    </script>
 
 <body>
 
    <form 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>
    

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

 

<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>
 
</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 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 = "Ads.xml"
           Borderwidth="1"
           Target="_blank"/>
 
   </form>
 
</body>
</html>


[C#] 

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

<html>
<head>
 
</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 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 = "Ads.xml"
           Borderwidth="1"
           Target="_blank"/>
 
   </form>
 
</body>
</html>

[C++] C++ のサンプルはありません。Visual Basic、C#、および JScript のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ

参照

AdRotator クラス | AdRotator メンバ | System.Web.UI.WebControls 名前空間 | AdCreated | AdCreatedEventHandler | AdCreatedEventArgs