Export (0) Print
Expand All
Expand Minimize

AdCreatedEventHandler Delegate

Represents the method that will handle the AdCreated event of an AdRotator control.

[Visual Basic]
<Serializable>
Public Delegate Sub AdCreatedEventHandler( _
   ByVal sender As Object, _
   ByVal e As AdCreatedEventArgs _
)
[C#]
[Serializable]
public delegate void AdCreatedEventHandler(
   object sender,
   AdCreatedEventArgs e
);
[C++]
[Serializable]
public __gc __delegate void AdCreatedEventHandler(
   Object* sender,
   AdCreatedEventArgs* e
);

[JScript] In JScript, you can use the delegates in the .NET Framework, but you cannot define your own.

Parameters [Visual Basic, C#, C++]

The declaration of your event handler must have the same parameters as the AdCreatedEventHandler delegate declaration.

sender
The source of the event.
e
An AdCreatedEventArgs that contains the event data.

Remarks

The AdCreated event is raised when the AdRotator displays an advertisement on the page.

When you create an AdCreatedEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event handler delegates, see Events and Delegates.

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 gets created and displays it below the control. This example requires the XML file (Ads.xml) listed in the example below.

[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 of the AdRotator class.

 <Advertisements>
 
    <Ad>
 
       <ImageUrl>images/image1.jpg</ImageUrl>
       <NavigateUrl>http://www.microsoft.com</NavigateUrl>
       <AlternateText>Microsoft Main Site</AlternateText>
       <LabelText>Microsoft Main</LabelText>
 
    </Ad>
 
    <Ad>
       <ImageUrl>images/image2.jpg</ImageUrl>
       <NavigateUrl>http://www.wingtiptoys.com</NavigateUrl>
       <AlternateText>Wingtip Toys Site</AlternateText>
       <LabelText>Wingtip Toys</LabelText>
    </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

Namespace: System.Web.UI.WebControls

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

Assembly: System.Web (in System.Web.dll)

See Also

System.Web.UI.WebControls Namespace | AdRotator | AdCreatedEventArgs | AdvertisementFile

Show:
© 2014 Microsoft