Share via


AdCreated Event

Occurs each time an advertisement is displayed.

public event AdCreatedEventHandler AdCreated

Remarks

The event handler receives an AdCreatedEventArgs property that contains the properties of the advertisement being displayed. The following table shows the properties that provide information specific to this event.

Property Description
AdProperties Returns the dictionary that contains all the advertisement properties extracted from an XML file after the OnAdCreated event is raised.
AlternateText Specifies the alternate text and ToolTip (if browser-supported) to be rendered in the AdRotator control.
ImageUrl Specifies the image to be rendered in the AdRotator control.
NavigateURL Specifies the URL reference that the browser navigates to when the advertisement is clicked.

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

Example

The following example demonstrates how to trap the AdCreated event to determine whether the user selected the default advertisement.

[Visual Basic]

<SCRIPT language="vb" runat="server">

Sub AdCreated_Event(sender As Object, e As System.Web.UI.WebControls.AdCreatedEventArgs)
   Dim defaultUrl As [String] = "https://www.microsoft.com"
   
   Label1.Text = "Clicking on AdRotator will take you to " + e.NavigateURL
   If e.NavigateURL = defaultUrl Then
      e.NavigateURL = "https://msdn.microsoft.com/vstudio/nextgen" + "/technology/mitdefault.asp"
   End If
   Label2.Text = "NavigateURL has changed to " + e.NavigateURL
End Sub

</SCRIPT>

<mobile:stylesheet id="Stylesheet1" runat="server" NAME="Stylesheet1">
<mobile:Style Font-Italic="True" Name="styForm">
<DeviceSpecific>
   <Choice>
      <HeaderTemplate>
         <mobile:Image runat="server" ImageUrl="default1.bmp" 
          NavigateURL="https://www.microsoft.com" AlternateText="Sample for 
          Device Specific" ID="Image1" NAME="Image1" />
         <mobile:AdRotator Alignment="Right" runat="server" id="AdrHeader" 
         AdvertisementFile="ads3.xml" OnAdCreated="AdCreated_Event" />
      </HeaderTemplate>
   </Choice>
</DeviceSpecific>
</mobile:Style>
</mobile:stylesheet><mobile:form id="Form1" runat="server" Stylereference="styForm">
<mobile:label id="Label1" runat="server"></mobile:label>
<mobile:label id="Label2" runat="server"></mobile:label>
<mobile:label id="Label3" runat="server" Text="Refresh the page to change the advertisement"></mobile:label>
</mobile:form>

<?xml version="1.0" ?>
<Advertisements>
    <Ad>
        <ImageUrl>gif1.gif</ImageUrl>
        <NavigateURL>https://msdn.microsoft.com/vstudio/nextgen/Technology/mitdefault.asp</NavigateURL>
        <AlternateText>Mobile Controls</AlternateText>
    </Ad>
    <Ad>
        <ImageUrl>gif2.gif</ImageUrl>
        <NavigateURL>https://www.microsoft.com</NavigateURL>
        <AlternateText>Microsoft</AlternateText>
    </Ad>
    <Ad>
        <ImageUrl>gif3.gif</ImageUrl>
        <NavigateURL>https://www.microsoft.com/net/</NavigateURL>
        <AlternateText>NET</AlternateText>
    </Ad>
</Advertisements>
<script language="c#" runat="server">

void AdCreated_Event(Object sender, 
   System.Web.UI.WebControls.AdCreatedEventArgs e)
{
   String defaultUrl = "https://www.microsoft.com";

   Label1.Text = "Clicking on AdRotator will take you to " + 
      e.NavigateURL;
   if (e.NavigateURL==defaultUrl)
   {
      e.NavigateURL="https://msdn.microsoft.com/vstudio/nextgen" +
        "/technology/mitdefault.asp";
   }
   Label2.Text = "NavigateURL has changed to " + e.NavigateURL;
}
</script>

<mobile:Stylesheet runat="server">
   <Style Name="styForm" Font-Italic = "true">
      <DeviceSpecific>
         <Choice>
            <HeaderTemplate>
               <mobile:Image runat="server" 
                  ImageUrl="default1.bmp" 
                  NavigateURL="https://www.microsoft.com" 
                  AlternateText="Sample for Device Specific" />
               <mobile:AdRotator Alignment="Right" runat="server"
                  id="AdrHeader" AdvertisementFile="ads3.xml" 
                  OnAdCreated="AdCreated_Event"/>
            </HeaderTemplate>
         </Choice>
      </DeviceSpecific>
   </Style>
</mobile:StyleSheet>

<mobile:Form runat="server" id="Form1" Stylereference="styForm">
   <mobile:label runat="server" id="Label1" />
   <mobile:label runat="server" id="Label2" />
   <mobile:label runat="server" id="Label3" 
      Text="Refresh the page to change the advertisement" />
</mobile:Form>

<?xml version="1.0" ?>
<Advertisements>
    <Ad>
        <ImageUrl>gif1.gif</ImageUrl>
        <NavigateURL>https://msdn.microsoft.com/vstudio/nextgen/Technology/mitdefault.asp</NavigateURL>
        <AlternateText>Mobile Controls</AlternateText>
    </Ad>
    <Ad>
        <ImageUrl>gif2.gif</ImageUrl>
        <NavigateURL>https://www.microsoft.com</NavigateURL>
        <AlternateText>Microsoft</AlternateText>
    </Ad>
    <Ad>
        <ImageUrl>gif3.gif</ImageUrl>
        <NavigateURL>https://www.microsoft.com/net/</NavigateURL>
        <AlternateText>NET</AlternateText>
    </Ad>
</Advertisements>

See Also

AdRotator Class