AdRotator Control in ASP.Net

In this article we are reading about AdRotator Control in ASP.Net.
The AdRotator is a special control in ASP.NET that is used to display flashing banner ads The control is capable of displaying ads randomly or sequentially as set by the user. Each time the page is refreshed or reloaded a new ad can be displayed to the user. Also, we can assign priorities in such a way that certain ads are displayed frequently than others.
The basic syntax of adding an AdRotator is as follows:
1
Before going into the details of the AdRotator control and its properties, let us look into the construction of the advertisement file.

The Advertisement File

The advertisement file is an XML file, which contains the information about the advertisements to be displayed.
Extensible Markup Language (XML) is a W3C standard for text document markup. It is a text-based markup language that enables you to store data in a structured format by using meaningful tags. The term ‘extensible’ implies that you can extend your ability to describe a document by defining meaningful tags for the application.
XML is not a language in itself, like HTML, but a set of rules for creating new markup languages. It is a meta-markup language. It allows developers to create custom tag sets for special uses. It structures, stores, and transports the information.
Following is an example of XML file:
1
2
3
Learn XML
Samuel Peterson
NSS Publications $30.00
Like all XML files, the advertisement file needs to be a structured text file with well-defined tags delineating the data. There are the following standard XML elements that are commonly used in the advertisement file:
ElementDescription
AdvertisementsEncloses the advertisement file.
AdDelineates separate ad.
ImageUrlThe path of image that will be displayed.
NavigateUrlThe link that will be followed when the user clicks the ad.
AlternateTextThe text that will be displayed instead of the picture if it cannot be displayed.
KeywordKeyword identifying a group of advertisements. This is used for filtering.
ImpressionsThe number indicating how often an advertisement will appear.
HeightHeight of the image to be displayed.
WidthWidth of the image to be displayed.
Apart from these tags, customs tags with custom attributes could also be included. The following code illustrates an advertisement file ads.xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
rose1.jpg
http://www.1800flowers.com
Order flowers, roses, gifts and more

20
flowers

rose2.jpg
http://www.babybouquets.com.au Order roses and flowers
20
gifts

rose3.jpg
http://www.flowers2moscow.com Send flowers to Russia
20
russia

rose4.jpg
http://www.edibleblooms.com Edible Blooms
20
gifts

Properties and Events of the AdRotator Class

The AdRotator class is derived from the WebControl class and inherits its properties. Apart from those, the AdRotator class has the following properties:
PropertiesDescription
AdvertisementFileThe path to the advertisement file.
AlternateTextFeildThe element name of the field where alternate text is provided. The default value is AlternateText.
DataMemberThe name of the specific list of data to be bound when advertisement file is not used.
DataSourceControl from where it would retrieve data.
DataSourceIDId of the control from where it would retrieve data.
FontSpecifies the font properties associated with the advertisement banner control.
ImageUrlFieldThe element name of the field where the URL for the image is provided. The default value is ImageUrl.
KeywordFilterFor displaying the keyword based ads only.
NavigateUrlFieldThe element name of the field where the URL to navigate to is provided. The default value is NavigateUrl.
TargetThe browser window or frame that displays the content of the page linked.
UniqueIDObtains the unique, hierarchically qualified identifier for the AdRotator control.
Following are the important events of the AdRotator class:
EventsDescription
AdCreatedIt is raised once per round trip to the server after creation of the control, but before the page is rendered
DataBindingOccurs when the server control binds to a data source.
DataBoundOccurs after the server control binds to a data source.
DisposedOccurs when a server control is released from memory, which is the last stage of the server control lifecycle when an ASP.NET page is requested
InitOccurs when the server control is initialized, which is the first step in its lifecycle.
LoadOccurs when the server control is loaded into the Page object.
PreRenderOccurs after the Control object is loaded but prior to rendering.
UnloadOccurs when the server control is unloaded from memory.

Working with AdRotator Control

Create a new web page and place an AdRotator control on it.
1
2
3
<form id="form1">
<div></div>
</form>
The ads.xml file and the image files should be located in the root directory of the web site.
Try to execute the above application and observe that each time the page is reloaded, the ad is changed.
So in this article we have read about “AdRotator Control in ASP.Net”.

Comments

Popular posts from this blog

Java Number Class

Java Character Class

What are Web Resources in Microsoft Dynamics 365?