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 控制項就不會快取。每當 Web 網頁重新整理時,新的廣告會被選取。不過,如果您提供 AdCreated 事件的事件處理常式,就不會選取新的廣告。
如需處理事件的詳細資訊,請參閱處理和引發事件。
下列程式碼範例示範如何為 AdCreated 事件指定及編碼處理常式。當 AdRotator 控制項建立時,它取得與廣告關聯的 URL,並將它顯示在控制項下面。
以下程式碼範例使用單一檔案程式碼模型,如果直接複製到程式碼後置 (Code-Behind) 檔案即可能無法作用。這個程式碼範例必須複製到副檔名為 .aspx 的空白文字檔。如需 Web Form 程式碼模型的詳細資訊,請參閱 ASP.NET Web 網頁程式碼模型。
<%@ 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.NavigateUrl 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.NavigateUrl; } </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.NavigateUrl; } </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> <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>~/Images/image2.jpg</ImageUrl> <Height>90</Height> <Width>90</Width> <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="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 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。