<%@ Page %>
Using AdRotator Web Control in ASP.NET
Introduction
We use banner or ad management techniques in many web pages. ASP.NET comes
with a Web Control called AdRotator which provides easy to use ad management
functionality. In earlier versions of ASP has provided similar component but
this version comes with a very easy and enhanced functionality. The ad file
format has also changed to XML. In this article we will see how we can use the
AdRotator web control to display banner ads.
Creating an instance of AdRotator Web control
<asp:AdRotator
id=AdRotator1
AdvertisementFile="C:\myads.xml" />
Here we have created an instance of AdRotator web control using
<asp:AdRotator> tags. The control has following main properties :
-
AdvertisementFile : This is a path of advertisement file which contains
information about various images.
-
Keywordfilter : AdRorator schedule file has a special tag called Keyword
which allows to filter ads based on certain words. This property specifies
that key word.
Creating Advertisement File
Advertisement file format has totally change as compared to previous
versions of ASP. Now the format is simple XML as follows :
myads.xml
<Advertisements>
<Ad>
<ImageUrl>c:\img1.jpg</ImageUrl>
<NavigateUrl>http://www.myhome.com</NavigateUrl>
<AlternateText>Welcome to my Home Page</AlternateText>
<Keyword>myname</Keyword>
<Impressions></Impressions>
</Ad>
<Ad>
<ImageUrl>c:\logo.gif</ImageUrl>
<NavigateUrl>http://www.myotherhome.com</NavigateUrl>
<AlternateText>Welcome again</AlternateText>
<Keyword>home</Keyword>
<Impressions></Impressions>
</Ad>
</Advertisements>
The file contains following main tags :
-
<Advertisements> which forms the root element
-
Each advertisement is enclosed
within <Ad> and
</Ad>
-
<ImageUrl> specifies path of the graphic file
-
<NavigateUrl> specifies the URL where user will be navigated on
clicking on the image
-
<AlternateText> specifies the text that appears on tooltip or if
any error occurs while displaying the image
-
<Keyword> specifies a specific work generally representing category
of the ad
-
<Impressions> specifies 'weight' this ad gets as compared to
others
Running A sample file
Simply create an aspx page with above code and run it in browser. Whenever
you refresh the page a new image will be displayed (depending on the weight you
have specified).