The AdRotator control selects ads randomly, changing the displayed ad each time the page is refreshed. Ads can be weighted to control the priority level of banners, making it possible to have certain ads display more often than others. You can also write custom logic that cycles through the ads.
AdRotator attributes:
ImageUrl: The URL of the image to display.
NavigateUrl: The URL of the page to go to when the AdRotator control is clicked.
AlternateText: The text to display if the image is unavailable.
Keyword: The category of the ad, which can be used to filter for specific ads.
Impressions: A numeric value (a weighting number) that indicates the likelihood of how often the ad is displayed. The total of all impressions values in the XML file cannot exceed 2,048,000,000 - 1.
Height : The height of the ad in pixels. This value overrides the default height setting for the AdRotator control.
Width: The width of the ad in pixels. This value overrides the default width setting for the AdRotator control.
To create an ad list as an XML file:
1. Select File => New Project
2. Then you can either use C# or Visual Basic (select web) to develop ASP.NET web applications.
3. Then Select ASP.NET Web Application
4. Give your project name and solution name.
5. Select the location, where you want the solution to be created.
6. Click OK.
A project will be appear below image
At this point right click WebApplication1 and then
1. Add=>New Item
2.Select XML file
3.Give your XML file name.
4.Finally click Add.
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>Ads\google.gif</ImageUrl>
<NavigateUrl>http://www.goole.com</NavigateUrl>
<AlternateText>google Logo</AlternateText>
<Keyword>A</Keyword>
<Impressions>Technology</Impressions>
<Caption>This is the caption for Ad#1</Caption>
</Ad>
<Ad>
<ImageUrl>Ads\youtube.gif</ImageUrl>
<NavigateUrl>http://www.youtube.com</NavigateUrl>
<AlternateText>www.goole.com</AlternateText>
<Keyword>S</Keyword>
<Impressions>Web Site</Impressions>
<Caption>This is the caption for Ad#2</Caption>
</Ad>
</Advertisements>
Create an Images folder in the project, and add the following images
Drag and Drop the AdRotator control on the webform. Set AdvertisementFile="~/Ads.xml"
<asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/Ads.xml" Target="_blank" />
Now run the application you will see above two images display randomly.





No comments:
Post a Comment