AdCreatedEventHandler 委托
表示处理 AdRotator 控件的 AdCreated 事件的方法。
**命名空间:**System.Web.UI.WebControls
**程序集:**System.Web(在 system.web.dll 中)
语法
声明
Public Delegate Sub AdCreatedEventHandler ( _
sender As Object, _
e As AdCreatedEventArgs _
)
用法
Dim instance As New AdCreatedEventHandler(AddressOf HandlerMethod)
public delegate void AdCreatedEventHandler (
Object sender,
AdCreatedEventArgs e
)
public delegate void AdCreatedEventHandler (
Object^ sender,
AdCreatedEventArgs^ e
)
/** @delegate */
public delegate void AdCreatedEventHandler (
Object sender,
AdCreatedEventArgs e
)
JScript 支持使用委托,但不支持进行新的声明。
参数
- sender
事件源。
- e
包含事件数据的 AdCreatedEventArgs。
备注
当 AdRotator 控件在页面上显示广告时,引发 AdCreated 事件。
创建 AdCreatedEventHandler 委托时,标识将处理事件的方法。若要使该事件与事件处理程序相关联,请将该委托的一个实例添加到事件中。除非移除了该委托,否则每当发生该事件时就调用事件处理程序。有关事件处理程序委托的更多信息,请参见 事件和委托。
示例
下面的代码示例演示如何为 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 = "~/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.href;
}
</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.href;
}
</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 文件的更多信息,请参见 AdRotator 类的 AdvertisementFile 属性。
<Advertisements>
<Ad>
<ImageUrl>images/image1.jpg</ImageUrl>
<href>https://www.microsoft.com</href>
<AlternateText>Microsoft Main Site</AlternateText>
<LabelText>Microsoft Main</LabelText>
</Ad>
<Ad>
<ImageUrl>images/image2.jpg</ImageUrl>
<href>http://www.wingtiptoys.com</href>
<AlternateText>Wingtip Toys Site</AlternateText>
<LabelText>Wingtip Toys</LabelText>
</Ad>
</Advertisements>
<%@ 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 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
System.Web.UI.WebControls 命名空间
AdRotator
AdCreatedEventArgs 类
AdvertisementFile