Windows Dev Center

Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

AdCreatedEventArgs.AdProperties Property

Gets a System.Collections.IDictionary object that contains all the advertisement properties for the currently displayed advertisement.

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

public IDictionary AdProperties { get; }

Property Value

Type: System.Collections.IDictionary
A System.Collections.IDictionary that contains a list of advertisement properties for the currently displayed advertisement. The default value is String.Empty.

Use the AdProperties property to get a System.Collections.IDictionary object that contains the advertisement properties for the currently displayed advertisement. The keys and values of the System.Collections.IDictionary object are of type System.String.

The AdRotator control randomly selects an advertisement each time the control is displayed on the Web page. The attributes for the selected advertisement are extracted from the advertisement XML file and stored in a System.Collections.IDictionary object. When the AdRotator control creates a new instance of the AdCreatedEventArgs class, the AdProperties property gets initialized with the System.Collections.IDictionary object.

Custom attributes about an advertisement, such as an advertisement caption, can also be included in the advertisement XML file. Use this property in the OnAdCreated event handler to get the custom attributes.

The following code example demonstrates how to use the AdProperties property in the OnAdCreated event handler to provide a custom caption.

<%@ Page Language="C#" AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
    <title>AdRotator Example</title>
</head>

    <script language="c#" runat="server">
       void AdCreated_Event(Object sender, AdCreatedEventArgs e) 
       {
          Message.Text=(string)e.AdProperties["Caption"];
       }      
    </script>

 <body>

    <form id="form1" 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>

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

The following code example demonstrates how to include custom attributes about an advertisement in the advertisement XML file. For more information on the XML file, see the AdvertisementFile property of the AdRotator class.

 <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>Wingtip Toys</AlternateText>
  <Impressions>80</Impressions>
  <Keyword>Topic2</Keyword>
  <Caption>This is the caption for Ad#2</Caption> 
  </Ad>
 </Advertisements>

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
Show:
© 2015 Microsoft