NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

AdRotator Web Control

The AdRotator Web control displays ad banners on Web pages. It changes the displayed ad each time the Web page is refreshed

ASP+ Syntax

Required properties are noted in boldface type.

<asp:AdRotator
   id=value
   runat="SERVER"
   AdvertisementFile="AdvertisementFile"
   propertyname=propertyvalue
   OnAdCreated="OnAdCreatedMethod"
>
</asp:AdRotator>

Properties

Property Description
(Base control properties) The properties defined in Base Web Control Properties.
AdvertisementFile The path to a well-formed XML file containing advertisement information. For information about the format of this file, see "Advertisement File Format" below.
KeywordFilter Indicates a category filter to pass to the source of ads, as follows:
  • If the ad source is specified in the AdvertisementFile property and the KeywordFilter property is set, an ad with a matching keyword will be selected.
  • If the ad source is specified in the AdvertisementFile property and the KeywordFilter property is set but no match exists, the AdRotator control will render as a blank image and a trace warning will be generated.
  • If the KeywordFilter property is empty, keyword filtering will not be used to select the ad.
Target Specifies the name of the browser window or frame in which to display the advertisement. This parameter can also be one of the HTML frame-keywords, such as _TOP, _NEW, _CHILD, _SELF, _PARENT, or _BLANK.

Events

Event (and paramters) Description
OnAdCreated(Object sender, AdCreatedEventArgs e) Raised on the server once per round trip, after control creation and immediately before the page is rendered. If an AdvertisementFile is provided, OnAdCreated is raised after an ad has been selected from the file.

Properties of the e events argument object:

  • e.AdProperties   (IDictionary) [???]
  • e.AlternateText   (string)
  • e.ImageUrl   (string)
  • e.NavigateUrl   (string)
  • For descriptions, see "Advertisement File Format" below.

Advertisement File Format

<?xml xmlns=”Ad Rotator Schedule” ?>
<Advertisements>
   <Ad>
      <ImageUrl>URL of image to display</ImageUrl>
      <TargetUrl> URL of page to link to </TargetUrl>
      <AlternateText>
         Text to show as ToolTip
       </AlternateText>
      <Keyword>keyword used to filter</Keyword>
      <Impressions>relative weighting of ad</Impressions>
   </Ad>
</Advertisements>

Note the following about creating an advertisement file:

Remarks

The AdRotator control renders as an image within an anchor. At runtime, AdRotator will use <asp:Hyperlink> and <asp:Image> controls to perform the rendering.

The source image will be sized by the browser to the dimensions of the AdRotator control, regardless of its actual size.

If the AdvertisementFile property is set, an ad is selected based on impressions weighting from the file, the event arguments are set, and the OnAdCreated event is raised. If the AdvertisementFile property is not set, the event arguments are empty when the OnAdCreated event is raised. The event arguments are used to render the AdRotator control, so you can modify the values passed to the event from the advertisement file, or set them with values you generate yourself. A common scenario is to populate the event arguments with values pulled from a database.

You can use the OnAdCreated event to select ads in your own code or to modify the rendering of an ad selected from the advertisement file. If an advertisement file is set, the arguments to the AdCreated event will already be set to the selected ad when the event is called. Whether or not the values are already set, you can modify the values in the ImageUrl, NavigateUrl, and AlternateText properties to modify the rendering of the AdRotator control.

Example

The following shows a sample declaration for an AdRotator control in an .aspx file.

<asp:AdRotator id="ar1" runat=server
   AdvertisementFile="Ads.xml"
   BorderWidth="1"
/>

The following example shows how you can create ad content at run time.

[Visual Basic]
Protected Sub AdRotator1_AdCreated(  s as object, _
       e as AdCreatedEventArgs)
   If Not IsEmpty(e.AdProperties("LabelText")) Then
      ' Set the caption label for the ad
      CaptionLabel.Text = e.AdProperties("LabelText")
   End If
End Sub

See Also

Web Forms Controls by Function |