AdRotator is one of ASP.NET’s rich web server controls. It is used to display the sequence of advertisement images according to the priority of the image. This control displays a sequence of images, specified in an external XML file. In an XML file we use images to display some other attributes, such as image impressions, NavigateUrl, ImageUrl, AlternateText etc.

Each time an Adrotator control images will be changed while refreshing the web page.

What is a server?

AdRotator control example in ASP.Net

Step 1 – Open Visual Studio -> Create a new empty web application.
Step 2 – Create a new web page to display it.
Step 3 – Drag and drop this controlĀ  from the toolbox to the web page.
Step 4 – Right click on Solution Explorer -> Add New Item -> Add a new XML file to the project to write advertisement detail.
Step 5 – Assign XML file for AdvertisementFile Property of it.

Now, let us consider adrotator control in ASP.NET by example

Adrotator Control in ASP.Net C #

Create a web application in asp.net and take an adrotator control on the following web forms: –

Now, add a new XML file from Add New Item.

Select the XML file, assign any name to the xml file, and click the Add button to add a new xml file to the website.

The XML file contains advertisement information.

Properties Description
ImageUrl It describes the path of the image that will be displayed in it.
NavigateUrl Describe the navigation webpage link when the user clicks on the ad image.
AlternateText The text will be displayed when the image is not displayed
Impressions Describe the display rate or priority of the image
Keyword This is a category of advertising (Ad).

Advertisement for Adrotator Control (Advertisement) XML file

Write the code for the advertisement in the xml file below.

<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
 <Ad>
 <ImageUrl>img/1.png</ImageUrl>
 <NavigateUrl>https://meeraacademy.com</NavigateUrl>
 <AlternateText>Meera Academy</AlternateText>
 <Impressions>50</Impressions>
 <Keyword>Meera</Keyword>
 </Ad>

 <Ad>
 <ImageUrl>img/2.png</ImageUrl>
 <NavigateUrl>http://meera.com</NavigateUrl>
 <AlternateText>Meerta Aademy</AlternateText>
 <Impressions>100</Impressions>
 <Keyword>Academy</Keyword>
 </Ad>
 <Ad>
 <ImageUrl>img/3.png</ImageUrl>
 <NavigateUrl>https://meeraacademy.com</NavigateUrl>
 <AlternateText>Meerta Aademy</AlternateText>
 <Impressions>50</Impressions>
 <Keyword>Academy</Keyword>
 </Ad>
</Advertisements>

Now, assign the XML file to the adrotator control in the AdvertisementFile property of the adrotator control.

The output of it is in c #. In the Adrotator control example above, we provide three images in the Advertisement xml file. When we refresh the webpage, we can see every time in the image below that the image of the advertisement will change.

.

LEAVE A REPLY

Please enter your comment!
Please enter your name here