AdRotator.AdCreated イベント
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)

Dim instance As AdRotator Dim handler As AdCreatedEventHandler AddHandler instance.AdCreated, handler
public: event AdCreatedEventHandler^ AdCreated { void add (AdCreatedEventHandler^ value); void remove (AdCreatedEventHandler^ value); }

AdvertisementFile プロパティが設定されている場合、広告がファイルから選択された後、このイベントは発生します。
イベント ハンドラは、表示されている広告のプロパティが格納されている AdCreatedEventArgs プロパティを受け取ります。このイベント固有の情報を提供するプロパティを次の表に示します。

AdCreated イベントを処理する次のコード例は、AdRotator クラスの概要で取り上げているコード例の一部です。

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


AdRotator.AdCreated イベント
アセンブリ: System.Web (system.web.dll 内)

Dim instance As AdRotator Dim handler As AdCreatedEventHandler AddHandler instance.AdCreated, handler
public: event AdCreatedEventHandler^ AdCreated { void add (AdCreatedEventHandler^ value); void remove (AdCreatedEventHandler^ value); }

このイベントは、作成されたコントロールがページ上に表示されるまでの間、サーバーへのラウンド トリップごとに 1 回発生します。AdvertisementFile プロパティが設定されている場合、このイベントは広告がファイルから選択された後で発生します。
AdCreated イベントのイベント ハンドラに渡された引数を変更することにより、AdRotator コントロールがどのように表示されるかを制御できます。AdvertisementFile プロパティが設定されていない場合は、別の広告ファイルを使用せずに、広告情報を直接指定できます。AdvertisementFile プロパティが設定されている場合は、別のページへのリダイレクトなど、AdRotator コントロールの動作を拡張できます。
![]() |
---|
ページ キャッシュが有効な場合、AdRotator コントロールはキャッシュされません。Web ページが更新されるたびに、新しい広告が選択されます。ただし、AdCreated イベントのイベント ハンドラが提供されている場合は、新しい広告は選択されません。 |
イベント処理の詳細については、「イベントの処理と発生」を参照してください。
Topic | Location |
---|---|
方法 : AdRotator Web サーバー コントロールでプログラムによって広告を選択する | ASP .NET Web アプリケーションの作成 |

AdCreated イベントのハンドラを指定およびコーディングする方法を次のコード例に示します。この例では、AdRotator コントロールが作成されたときに広告に関連付けられた URL を取得して、次にその URL を表示します。
![]() |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ 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.NavigateUrl End Sub </script> <body> <form 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" %> <html> <head> </head> <script language="C#" runat="server"> void AdCreated_Event(Object sender, AdCreatedEventArgs e) { Message.Text=e.NavigateUrl; } </script> <body> <form 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" %> <html> <head> </head> <script language="JScript" runat="server"> function AdCreated_Event(sender, e : AdCreatedEventArgs) { Message.Text=e.NavigateUrl; } </script> <body> <form 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> <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>~/Images/image2.jpg</ImageUrl> <Height>90</Height> <Width>90</Width> <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>
![]() |
---|
次のコード サンプルはシングルファイル コード モデルを使用しており、分離コード ファイルに直接コピーされた場合は正常に動作しない可能性があります。このコード サンプルは、拡張子が .aspx の空のテキスト ファイルにコピーする必要があります。Web フォームのコード モデルの詳細については、「ASP.NET Web ページのコード モデル」を参照してください。 |
<%@ 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 = "~/App_Data/Ads.xml" Borderwidth="1" Target="_blank"/> </form> </body> </html>
<%@ 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 = "~/App_Data/Ads.xmla" Borderwidth="1" Target="_blank"/> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- AdRotator.AdCreatedのページへのリンク