The AdRotator Web control displays ad banners on Web pages. It changes the displayed ad each time the Web page is refreshed
Required properties are noted in boldface type.
<asp:AdRotator id=value runat="SERVER" AdvertisementFile="AdvertisementFile" propertyname=propertyvalue OnAdCreated="OnAdCreatedMethod" > </asp:AdRotator>
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:
|
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. |
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:
|
<?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:
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.
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