AdRotator control in ASP.NET

AdRotator control

AdRotator control are used to create a dynamic ads. The AdRotator Control presents ad images each time a user enters or refreshes a webpage. When the ads are clicked, it will navigate to a new Web location. The AdRotator control is used to display a sequence of ad images.The AdRotator control to work we need an Advertisement file (XML file) and some sample images.

Adding the AdRotator web server control to your web application. first, select the AdRotator and drag and drop the control to your web form. Map the XML file which contains the details about each and every ad.

The advertisement file is an XML file. The following are some of the elements of this XML file.

1. <imageUrl>: Optional. The path to the image file.
2. <NavigateUrl>: Optional. The URL to link to if the user clicks the ad.
3. <AlternateText>: Optional. An alternate text for the image.
4. <Impressions>: Optional. The display rates in percent of the hits.

XML code that has the details about the ads. The file Ads.xml looks like the code below:





    <AlternateText>Cat 2</AlternateText>






    <AlternateText>Cat 3</AlternateText>






    <AlternateText>Cat 4</AlternateText>




Now click AdRotator1 and then press the F4 key to view its properties.

Set the AdvertisementFile property to file name myads.xml.

Save and build the project.

Creating AdRotator Control At Runtime

The PlaceHolder control enables you to place an empty container control in the page and then dynamically add child elements to it at run time.

AdRotator rotator = new AdRotator();
rotator.AdvertisementFile = "AdRotatorFiles.xml";

How To Filter Advertisement

1. Select adrotator control and view its properties.
2. Set the KeywordFilter property to Support.
3. Save and Build the project.
4. View the page in Browser. Check that only the advertisements with the keyword Support appear.

Ebook Download
View all
View all