Home >> ASP.NET >> How to display Ads using AdRotator in ASP.NET

How to display Ads using AdRotator in ASP.NET


Few days ago, while answering a forum thread, there was a question about displaying banners in ASP.NET. Actually Banner word is widely used among Joomla user. Joomla is a award winning Open Source CMS powering most of the powerful, larger and complex websites. Joomla has builtin module for showing promotional banners in graphical format. You have to define an image and target URL for that banner.

In ASP.NET framework, we can also display the Advertisements using a control named AdRotator. AdRotator is one of the standard server side control available with Visual Studio from long time. In this article I will try to demonstrate the procedure of using AdRotator in ASP.NET with the XML file as Data Source.


  • Visual Studio 2005 or higher. We are using Visual Studio 2013 in this article.
  • Images used to display at frontend.
  • Skill Level: Beginner

Using AdRotator in ASP.NET Design

We have created a simplest design as possible. Just a Heading and AdRotator control. Here is the structure of Solution Explorer for this project.

Using AdRotator in ASP.NET Solution Explorer
Using AdRotator in ASP.NET – Solution Explorer

We have created a folder named Ads and then again created a folder inside newly created folder to put images wit the relevant name of images. We also added a XML File which will be our data source for serving ads. Also We have taken some screenshots of website and paste them inside images folder. Again we have added a New Web Form which will contain the AdRotator control to serve ads.

Now here is the Code of ASPX page for design as image 1 in this article.

In the above code snippet, We have added a AdRotator Control from Controls, set BorderWidth property to 1px so that it can be identified. Also we have fixed the height and width of control (banner) so in case images are larger, we will not face any kind of alignment problem with content.

As earlier mentioned, AdRotator control is server side control that works from DataSource, so we have taken a XML datasource with link to XML file.

Now lets have a look at our DataSource XML file structure.

Now the most important, what the above XML Node and their content are.
Lets understand first, An Advertisement Node for AdRotator can have following attributes.

  1. ImageURL : This is the path to Image. Image can be of any standard format and might be located to local server or remote server.
  2. NavigateUrl : This is the path where user will be redirected when clicked in Ad.
  3. AlternateText : Alternate Text is a text that will work same as alt in case of img tag of HTML. This will display the text specified if image is not available for any reason.
  4. Keyword : Keywords are used to filter ads sometimes.
  5. Impression : This is the repeat value in simple word. You can define how often that ad will be served. In above case we have set the impression value same for all 3 ads which case each time user reloads page, he will be served different ad. Suppose, if we had set impression value of first ad to 30 and other’s 10, then first will be served three time while others will be served once.
  6. Height : Height of the Ad to be displayed. This will override the values specified in control.
  7. Width : Width of the ad to be displayed. This will override the values specified in control.

So we have escaped attributes Height and Width here because we have already defined this in Control.

No more work to do, lets have look at browser. We got below screens each time we reload page, We get different ad. Lets have a look at outputs of above design and code.

Demo : Follow Link

Source Code:
Follow Link
Do not forget to provide feedback on above post. We will be glad to head. You can contribute by sharing our article if this helped in any manner.

About John Bhatt

Aka, Prithvi Raj Bhatt, A Proud Nepali, Blogger, Software Developer, ASP.NET, Web Designer & Developer, Faculty and a Troubleshooter blog @PRsBlog

Check Also


Google AdSense with WordPress

Hi, As in our last post, I informed you about the migration from Blogger hosted …

Leave a Reply

Your email address will not be published. Required fields are marked *