Monday, 15 July 2013

AdRotator in ASP.NET.



The ASP.NET AdRotator web server control is a useful control to randomly display clickable ad banners / advertisements from a list on a web page, which is specified in an external XML schedule file. This external XML schedule file is called the advertisement file.
The XML file must begin and end with an <Advertisements> tag. Inside the <Advertisements> tag there may be several <Ad> tags which defines each ad.

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.
The predefined elements inside the <Ad> tag are listed below:
Element
Description
<ImageUrl>
Optional. The path to the image file
<NavigateUrl>
Optional. The URL to link to if the user clicks the ad
<AlternateText>
Optional. An alternate text for the image
<Keyword>
Optional. A category for the ad
<Impressions>
Optional. The display rates in percent of the hits


Properties:
The AdRotator class is derived from the WebControl class and inherits its properties. Apart from those the AdRotator class has the following properties:
Property
Description
AdvertisementFile
Specifies the path to the XML file that contains ad information
AlternateTextField
Specifies a data field to be used instead of the Alt text for an ad
DataMember
The name of the specific list of data to be bound when advertisement file is not used.
DataSource
Control from where it would retrieve data.
DataSourceID
Id of the control from where it would retrieve data.
Font
Specifies the font properties associated with the advertisement banner control.
ImageUrlField
Specifies a data field to be used instead of the ImageURL attribute for an ad
KeywordFilter
Specifies a filter to limit ads after categories
NavigateUrlField
Specifies a data field to be used instead of the NavigateUrl attribute for an ad
runat
Specifies that the control is a server control. Must be set to "server"
Target
Specifies where to open the URL
UniqueID
Obtains the unique, hierarchically qualified identifier for the AdRotator control.

Following are the important events of the AdRotator Class:

Events
Description
AdCreated
It is raised once per round trip to the server after creation of the control, but before the page is rendered
DataBinding
Occurs when the server control binds to a data source.
DataBound
Occurs after the server control binds to a data source.
Disposed
Occurs 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
Init
Occurs when the server control is initialized, which is the first step in its lifecycle.
Load
Occurs when the server control is loaded into the Page object.
PreRender
Occurs after the Control object is loaded but prior to rendering.
Unload
Occurs when the server control is unloaded from memory.

No comments:

Post a Comment