<%@ Page %>

Using AdRotator Web Control in ASP.NET


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

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 :


      <AlternateText>Welcome to my Home Page</AlternateText>
      <AlternateText>Welcome again</AlternateText>


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).

Bipin Joshi is an independent software consultant and trainer by profession specializing in Microsoft web development technologies. Having embraced the Yoga way of life he is also a meditation teacher and spiritual guide to his students. He is a prolific author and writes regularly about software development and yoga on his websites. He is programming, meditating, writing, and teaching for over 27 years. To know more about his ASP.NET online courses go here. More details about his Kriya and Meditation online course are available here.

Posted On : 08 April 2001

Tags : ASP.NET Server Controls