This documentation is archived and is not being maintained.

AdRotator.AdCreated Event

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

[Visual Basic]
Public Event AdCreated As AdCreatedEventHandler
[C#]
public event AdCreatedEventHandler AdCreated;
[C++]
public: __event AdCreatedEventHandler* AdCreated;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type AdCreatedEventArgs containing data related to this event. The following AdCreatedEventArgs properties provide information specific to this event.

Property Description
AdProperties Gets a System.Collections.IDictionary object that contains all the advertisement properties for the currently displayed advertisement.
AlternateText Gets or sets the alternate text displayed in the AdRotator control when the advertisement image is unavailable. Browsers that support the ToolTips feature display this text as a ToolTip for the advertisement.
ImageUrl Gets or sets the URL of an image to display in the AdRotator control.
NavigateUrl Gets or sets the Web page to display when the AdRotator control is clicked.

Remarks

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

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 to extend the behavior of the AdRotator control, such as redirecting to another page.

Note   If the AdvertisementFile property is set, this event occurs after the advertisement has been selected from the file.

For more information about handling events, see Consuming Events.

Example

[Visual Basic, C#, JScript] The following 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. You need to create an XML file called Ads.xml that contains the code listed in the second example. The Ads.xml file needs to reside in the same directory as the source file for this example.

[Visual Basic] 
<%@ 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 = "Ads.xml"
            Borderwidth="1"
            Target="_newwwindow"
            OnAdCreated="AdCreated_Event"/><br><br>
 
       <asp:label id="Message" runat="server"/>
 
    </form>
 
 </body>
 </html>
    

[C#] 
<%@ 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 = "Ads.xml"
            Borderwidth="1"
            Target="_newwwindow"
            OnAdCreated="AdCreated_Event"/><br><br>
 
       <asp:label id="Message" runat="server"/>
 
    </form>
 
 </body>
 </html>
    

[JScript] 
<%@ 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 = "Ads.xml"
            Borderwidth="1"
            Target="_newwwindow"
            OnAdCreated="AdCreated_Event"/><br><br>
 
       <asp:label id="Message" runat="server"/>
 
    </form>
 
 </body>
 </html>
    

[Visual Basic, C#, JScript] The following example demonstrates how to format the XML file that contains the advertisement information. For additional information on the XML file, see the AdvertisementFile property.

<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>Wing Tip Toys</AlternateText>
 <Impressions>80</Impressions>
 <Keyword>Topic2</Keyword>
 <Caption>This is the caption for Ad#2</Caption> 
 </Ad>
 
</Advertisements>
[Visual Basic] 

<%@ 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 = "Ads.xml"
           Borderwidth="1"
           Target="_blank"/>
 
   </form>
 
</body>
</html>


[C#] 

<%@ 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 = "Ads.xml"
           Borderwidth="1"
           Target="_blank"/>
 
   </form>
 
</body>
</html>

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

AdRotator Class | AdRotator Members | System.Web.UI.WebControls Namespace | OnAdCreated | AdCreatedEventHandler | AdCreatedEventArgs

Show: