The AdRotator control is an ASP.NET rich control that is used to create and manipulate banner advertisements in Web pages. It can automatically rotate through a series of advertisements, displaying each with the specified frequency. The properties of the banner advertisements to be displayed by the control are specified in an XML file.
The properties, methods, and events of the AdRotator control are shown in table:
Property | Description |
---|---|
AdvertisementFile | The path to the XML file that contains the banner advertisements to be displayed. |
KeywordFilter | Only the advertisements matching the set filter are returned. |
Target | When the user clicks the advertisement, the page is opened in this window or frame.possible values are _top, _new, _child, _self, _parent, _blank. |
Methods | Description |
OnAdCreated | Raises the AdCreated event. |
Events | Description |
AdCreated | Raised after an advertisement is retrieved from the file and before it is rendered. |
The format of the XML advertisement file is described below.
<Advertisements> <Ad> <ImageUrl>URL of Image to Display</ImageUrl> <NavigateUrl>URL of Page to Link to</NavigateUrl> <AlternateText>Text to show as ToolTip</AlternateText> <Keyword>Keyword used to Filter</Keyword> <Impressions>Relative weight of ad</Impressions> </Ad> </Advertisements>
The properties of an advertisement are described below. All except the ImageUrl are optional.
Example 1: Advertisement.xml
<Advertisements> <Ad> <ImageUrl>/images/flwaway.jpg</ImageUrl> <NavigateUrl>http://www.rediff.com</NavigateUrl> <AlternateText>Go To Rediff.Com</AlternateText> <Keyword>E-Mail</Keyword> <Impressions>80</Impressions> </Ad> <Ad> <ImageUrl>/images/ms.jpg</ImageUrl> <NavigateUrl>http://www.microsoft.com</NavigateUrl> <AlternateText>Go To Microsoft.Com</AlternateText> <Keyword>E-Mail</Keyword> <Impressions>60</Impressions> </Ad> </Advertisements>
AdRotator.aspx
<html> <head> <title>AdRotator Control</title> </head> <form runat="server"> <asp:AdRotator id="ar1" Target="_self" AdvertisementFile="advertisement.xml" BorderWidth="1" runat="server"/> </form> </html>