AdCreatedEventArgs 類別

定義

提供 AdCreated 控制項的 AdRotator 事件資料。 此類別無法獲得繼承。

public ref class AdCreatedEventArgs sealed : EventArgs
public ref class AdCreatedEventArgs : EventArgs
public sealed class AdCreatedEventArgs : EventArgs
public class AdCreatedEventArgs : EventArgs
type AdCreatedEventArgs = class
    inherit EventArgs
Public NotInheritable Class AdCreatedEventArgs
Inherits EventArgs
Public Class AdCreatedEventArgs
Inherits EventArgs
繼承
AdCreatedEventArgs

範例

下列程式碼範例示範如何指定 和 撰寫 AdCreated 事件的處理常式程式碼。 它會在控制項建立時 AdRotator 取得與公告相關聯的 URL,並在控制項下方顯示。 此範例需要下列範例所列的 XML 檔案 (Ads.xml) 。

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
    <title>AdRotator Example</title>
</head>
 
    <script language="c#" runat="server">
       void AdCreated_Event(Object sender, AdCreatedEventArgs e) 
       {
          Message.Text=e.NavigateUrl;   
       }      
    </script>
 
 <body>
 
    <form id="form1" 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="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
    <title>AdRotator Example</title>
</head>
 
    <script language="vb" runat="server">
       Sub AdCreated_Event(sender As Object, e As AdCreatedEventArgs) 
          Message.Text=e.NavigateUrl
       End Sub
    </script>
 
 <body>
 
    <form id="form1" 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 類別的 AdRotator 屬性。

<Advertisements>  
 <Ad>  
 <ImageUrl>image1.jpg</ImageUrl>  
 <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>image2.jpg</ImageUrl>  
 <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>  

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AdRotator AdCreated Example</title>
</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 id="form1" 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="VB" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>AdRotator AdCreated Example</title>
</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 id="form1" 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>

備註

AdCreated當控制項在頁面上顯示廣告時 AdRotator ,就會引發 事件。

如需 實例 AdCreatedEventArgs 的初始屬性值清單,請參閱 建 AdCreatedEventArgs 構函式。

如需處理事件的詳細資訊,請參閱 處理和引發事件

建構函式

AdCreatedEventArgs(IDictionary)

初始化 AdCreatedEventArgs 類別的新執行個體。

屬性

AdProperties

取得 IDictionary 物件,包含目前所顯示廣告的所有廣告屬性。

AlternateText

取得或設定在沒有廣告影像時,顯示於 AdRotator 控制項的替代文字。 支援工具提示功能的瀏覽器會將這個文字顯示為廣告的工具提示。

ImageUrl

取得或設定 AdRotator 控制項中顯示的影像的 URL。

NavigateUrl

取得或設定按一下 AdRotator 控制項時,所要顯示的 Web 網頁。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱