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:
<Advertisements>
<Ad>
<ImageUrl>adimages/2.jpg</ImageUrl>
<NavigateUrl>http://cat2.com</NavigateUrl>
<AlternateText>Cat
2</AlternateText>
<Impressions>30</Impressions>
</Ad>
<Ad>
<ImageUrl>adimages/3.jpg</ImageUrl>
<NavigateUrl>http://cat3.com</NavigateUrl>
<AlternateText>Cat
3</AlternateText>
<Impressions>20</Impressions>
</Ad>
<Ad>
<ImageUrl>adimages/4.jpg</ImageUrl>
<NavigateUrl>http://cat4.com</NavigateUrl>
<AlternateText>Cat
4</AlternateText>
<Impressions>10</Impressions>
</Ad>
</Advertisements>
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";
PlaceHolder1.Controls.Add(rotator);
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.