A common use of graphics is for advertisements - most Internet ads are stored as .gif files. Visual Studio includes the AdRotator control
to handle the tasks associated with displaying these types of ads. The AdRotator control uses an XML file to schedule the ads that are
displayed. The XML file stores the URL of the advertisement's image, the URL of the page to display if the user clicks the ad, the priority of
the ad, and other properties of the ad. Ad run time, the AdRotator control selects one of the ads listed in its XML file and displays it on the page
To use the AdRotator control, follow these steps:
1. Draw an AdRotator control on a Web form
2. Add an XML file to the current project and open it
3. In the Properties window, select the "TargetSchema" property, and then select AdRotator Schedule File from the drop-down list of
property settings. Visual Studio adds the following lines to the XML file:
<Advertisements xmlns="http://schemas.microsoft.com/AspNet/AdRotator-Schedule-File"></Advertisements>
4. Add <Ad> tags to the <Advertisements> section ofthe XML file for each ad you want to display
5. Save the XML file, and switch back to the Web form in Design view.
6. Select the AdRotator control, and set the "AdvertisementsFile" property to the XML file you just created
Now edit the XML file to display the desired information. For example, the following XML file displays two different ads:
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements xmlns="http://schemas.microsoft.com/AspNet/AdRotator-Schedule-File">
<Ad>
<ImageUrl>../ads/sponsorad.gif</ImageUrl>
<NavigateUrl>/ads/sponsorad.htm</NavigateUrl>
<AlternateText>Click here to visit our sponsor.</AlternateText>
<Keyword></Keyword>
<Impressions>1</Impressions>
</Ad>
<Ad>
<ImageUrl>../ads/net.gif</ImageUrl>
<NavigateUrl>//www.gotdotnet.com</NavigateUrl>
<AlternateText>ASP.NET tutorials and more</AlternateText>
<Keyword>ASP</Keyword>
<Impressions>5</Impressions>
</Ad>
</Advertisements>
The tags in the AdRotator XML schema are defined below:
<Ad> Begins an ad
<ImageUrl> The address of the ad to display
<NavigateUrl> The address to navigate to if the user clicks the ad
<AlternateText> The text to display in a ToolTip if the user pauses the mouse over the ad. Also, if the ad at the ImageUrl
address can't be displayed, this text appears in its place
<Keyword> A category name to use for filtering the ads to display
<Impressions> A number represeneting the likelihood that an ad will be displayed. Ads with higher numbers are more likely
to be displayed