AdRotator.AdCreated 事件
在控件创建后、呈现页面前,在每个到服务器的往返行程过程中发生一次。
**命名空间:**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 支持使用事件,但不支持进行新的声明。
备注
在控件创建后、呈现页面前,每个到服务器的往返行程引发一次此事件。如果设置了 AdvertisementFile 属性,则该事件将在从文件中选择了广告之后发生。
您可以通过修改传递给 AdCreated 事件的事件处理程序的参数来控制 AdRotator 控件的显示方式。如果未设置 AdvertisementFile 属性,这使您可以直接指定公布信息而无需使用单独的公布文件。如果设置了 AdvertisementFile 属性,这使您可以扩展 AdRotator 控件的行为(如重定向到另一页)。
提示
在启用页缓存的情况下,AdRotator 控件不会被缓存。每当网页刷新时就选择新的公布。但是,如果为 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 网页代码模型。
<%@ 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 文件的更多信息,请参见 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 网页代码模型。
<%@ 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
请参见
参考
AdRotator 类
AdRotator 成员
System.Web.UI.WebControls 命名空间
OnAdCreated
AdCreatedEventHandler 委托
AdCreatedEventArgs 类