AdRotator コントロールの AdCreated イベントを処理するメソッドを表します。
<Serializable>
Public Delegate Sub AdCreatedEventHandler( _ ByVal sender As Object, _ ByVal e As AdCreatedEventArgs _)
[C#]
[Serializable]
public delegate void AdCreatedEventHandler( object sender, AdCreatedEventArgs e);
[C++]
[Serializable]
public __gc __delegate void AdCreatedEventHandler( Object* sender, AdCreatedEventArgs* e);
[JScript] JScript では、.NET Framework のデリゲートを利用することができます。ただし、独自に定義することはできません。
パラメータ [Visual Basic, C#, C++]
作成するイベント ハンドラは、AdCreatedEventHandler クラスのデリゲート定義と同一のパラメータを持つ必要があります。
- sender
イベントのソース。 - e
イベント データを格納している AdCreatedEventArgs 。
解説
AdRotator によってページに広告が表示されると AdCreated イベントが発生します。
AdCreatedEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを指定します。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。イベント ハンドラ デリゲートの詳細については、「 イベントとデリゲート 」を参照してください。
使用例
[Visual Basic, C#, JScript] AdCreated イベントのハンドラを指定およびコード化する方法を次の例に示します。この例では AdRotator コントロールが作成されたときに広告に関連付けられた URL を取得して、次にその URL を表示します。この例では、例の中でリストされている 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 ファイルの詳細については、 AdRotator クラスの 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 のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
名前空間: System.Web.UI.WebControls
プラットフォーム: Windows 2000, Windows XP Professional, Windows Server 2003 ファミリ
アセンブリ: System.Web (System.Web.dll 内)
参照
System.Web.UI.WebControls 名前空間 | AdRotator | AdCreatedEventArgs | AdvertisementFile