AdCreatedEventArgs 类

AdRotator 控件的 AdCreated 事件提供数据。无法继承此类。

**命名空间:**System.Web.UI.WebControls
**程序集:**System.Web(在 system.web.dll 中)

语法

声明
Public Class AdCreatedEventArgs
    Inherits EventArgs
用法
Dim instance As AdCreatedEventArgs
public class AdCreatedEventArgs : EventArgs
public ref class AdCreatedEventArgs : public EventArgs
public class AdCreatedEventArgs extends EventArgs
public class AdCreatedEventArgs extends EventArgs

备注

AdRotator 控件在页面上显示广告时,引发 AdCreated 事件。

有关 AdCreatedEventArgs 的实例的初始属性值列表,请参见 AdCreatedEventArgs 构造函数。

有关处理事件的更多信息,请参见 事件和委托

主题 位置
如何:以编程方式在 AdRotator Web 服务器控件中选择广告 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:以编程方式在 AdRotator Web 服务器控件中选择广告 在 Visual Studio 中生成 ASP .NET Web 应用程序
如何:以编程方式在 AdRotator Web 服务器控件中选择广告 生成 ASP .NET Web 应用程序

示例

下面的代码示例演示如何为 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>image1.jpg</ImageUrl>
  <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>image2.jpg</ImageUrl>
  <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>
<%@ 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>

继承层次结构

System.Object
   System.EventArgs
    System.Web.UI.WebControls.AdCreatedEventArgs

线程安全

此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。

平台

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

请参见

参考

AdCreatedEventArgs 成员
System.Web.UI.WebControls 命名空间
AdCreatedEventHandler
AdRotator
AdvertisementFile