Reader Level:
ARTICLE

How to Use AdRotator in ASP.NET

Posted by Shubham Saxena Articles | ASP.NET Programming July 17, 2012
In this article I will tell you how to use AdRotator in your page.
  • 1
  • 0
  • 24397
Download Files:
 

AdRotator is a control in ASP.Net which is concerned with advertisements; it basically displays a sequence of ad images. This control uses an XML file to store the ad information. 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 (we will see a sample XML in this article).

In this article I will tell you how to use an AdRotator in your page. First step, create an "ASP.NET Empty Web Application".

AdRtr1.jpg

Since we have begun with an Empty Web Application we need to add a page now. Go to Project > Add New Item (Ctrl+Shift+A); a screen will popup; add a web form from it and name it "AdRotator.aspx".

AdRtr2.jpg

We should also add an XML file which will contain ad information. Go to Project > Add New Item (Ctrl+Shift+A); select "Data" from the left and add a XML file, name it "AdRotator.xml".

AdRtr3.jpg

Now we will write our XML file; it begins and ends with an <Advertisements> tag. Inside the <Advertisements> tag there may be several <Ad> tags which defines each ad. 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

But before we add content to our XML file we need to have ad images, so create a new folder in Solution Explorer and name it 'Images' and drag your ad images to it. The code snippet for the XML file is shown below:

AdRtr4.jpg

Now, from the Solution Explorer open AdRotator.aspx page it will contain some default code, we will add the AdRotator control now either by dragging it from the Toolbox or writing its code, we will also use some attributes for it like Advertisement File (which specifies the path to the XML file that contains the ad information) and Target (specifies where to open the URL).

AdRtr5.jpg

That is all. Debug your project and see it working. I have just added 3 images so you might often see the same image; add more images and see it rolling. In addition to advertisements this can also be used as a banner for your website and for many more purposes.

Article Extensions
Contents added by priksht Sharma on Sep 17, 2012
COMMENT USING

Trending up