This documentation is archived and is not being maintained.

AdCreated Event

.NET Framework 1.1

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] = "http://www.microsoft.com"
   
   Label1.Text = "Clicking on AdRotator will take you to " + e.NavigateUrl
   If e.NavigateUrl = defaultUrl Then
      e.NavigateUrl = "http://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="http://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>http://msdn.microsoft.com/vstudio/nextgen/Technology/mitdefault.asp</NavigateUrl>
        <AlternateText>Mobile Controls</AlternateText>
    </Ad>
    <Ad>
        <ImageUrl>gif2.gif</ImageUrl>
        <NavigateUrl>http://www.microsoft.com</NavigateUrl>
        <AlternateText>Microsoft</AlternateText>
    </Ad>
    <Ad>
        <ImageUrl>gif3.gif</ImageUrl>
        <NavigateUrl>http://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 = "http://www.microsoft.com";

   Label1.Text = "Clicking on AdRotator will take you to " + 
      e.NavigateUrl;
   if (e.NavigateUrl==defaultUrl)
   {
      e.NavigateUrl="http://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="http://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>http://msdn.microsoft.com/vstudio/nextgen/Technology/mitdefault.asp</NavigateUrl>
        <AlternateText>Mobile Controls</AlternateText>
    </Ad>
    <Ad>
        <ImageUrl>gif2.gif</ImageUrl>
        <NavigateUrl>http://www.microsoft.com</NavigateUrl>
        <AlternateText>Microsoft</AlternateText>
    </Ad>
    <Ad>
        <ImageUrl>gif3.gif</ImageUrl>
        <NavigateUrl>http://www.microsoft.com/net/</NavigateUrl>
        <AlternateText>NET</AlternateText>
    </Ad>
</Advertisements>

See Also

AdRotator Class

Show: