Export (0) Print
Expand All

AdRotator.AdCreated Event

Occurs once per round trip to the server after the creation of the control, but before the page is rendered.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public event AdCreatedEventHandler AdCreated
/** @event */
public void add_AdCreated (AdCreatedEventHandler value)

/** @event */
public void remove_AdCreated (AdCreatedEventHandler value)

JScript supports the use of events, but not the declaration of new ones.

This event is raised once per round trip to the server after the creation of the control, but before the page is rendered. When the AdvertisementFile property is set, this event occurs after the advertisement has been selected from the file.

You can control how the AdRotator control is displayed by modifying the arguments passed to the event handler of the AdCreated event. If the AdvertisementFile property is not set, this allows you to specify the advertisement information directly, without using a separate advertisement file. If the AdvertisementFile property is set, this allows you to extend the behavior of the AdRotator control, such as redirecting to another page.

NoteNote

When page caching is enabled, an AdRotator control is not cached. A new advertisement is selected whenever the Web page refreshes. A new advertisement is not selected, however, if you provide an event handler for the AdCreated event.

For more information about handling events, see Handling and Raising Events.

The following code example demonstrates how to specify and code a handler for the AdCreated event. It gets the URL associated with the advertisement, when the AdRotator control is created, and displays it below the control.

NoteNote

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.

<%@ 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>
    

The following code example demonstrates how to format the XML file that contains the advertisement information. For more information on the XML file, see the AdvertisementFile property.

<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>
NoteNote

The following code sample uses the single-file code model and may not work correctly if copied directly into a code-behind file. This code sample must be copied into an empty text file that has an .aspx extension. For more information on the Web Forms code model, see ASP.NET Web Page Code Model.


<%@ 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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft