SIGN UP MEMBER LOGIN:    
ARTICLE

AdRotator Control For Web Pages

Posted by Sivaraman Dhamodaran Articles | ASP.NET Controls in C# July 18, 2011
In this article we will have a look at what the AdRotator control is and how it is used in web pages. Also we will explore the XML file that supplies advertisement content.
Reader Level:
Download Files:
 

1. Introduction

 

The AdRotator control is useful for displaying advertisements. This control acts as a placeholder for the image and the image is actually a link to the advertised web site. So when an image displayed by the AdRotator control is clicked, the user will navigate to the link that corresponds to that advertised image.

 

To use AdRotator images to the external sites to be created. Then an xml file tells the AdRotator which site should be navigated to when the image is clicked.

 

2. About the Sample

 

The sample two pages consistsw of a Main page with a link to the content page and the content page has a Go Back link to the main page. The content page is a copy of a Mahatma Gandhi image taken from the wiki page. This page has two AdRotator controls. Have a look at the following illustration:

  Pic01.JPG
The main page navigates to the content page and the content back page navigates back to the main page through a link provided in the pages. The content page displays the advertisement using the AdRotator control. The AdvertisementFile property of the AdRotator control looks for the xml file, which informs the control about the advertisement details.

 

The following screen shot shows the main page:


Pic02.JPG

 

Clicking the "Here" hyperlink will navigate you through the content page. The screen shot of the content page is below:

 

Pic03.JPG

 

This page has the Go Back link and the link will bring you to the Main page. The page has information about the Gandhi and it displays two advertisements above and below the Gandhi's pictures.  The xml file set to the AdvertisementFile property displays the advertisements selectively. Each time you come to the page the same or a different advertisement is displayed in the advertisement control.

 

3. Images for the Ads

 

First the banners are created for this sample by visiting the site and taking a screen shot. These images are used as ad banners and placed in the folder (Created) AdImages. Then all the images are added to the ASP.Net project using the Add item content menu.

 

Pic04.JPG

 

4. The XML file

 

The xml file supplies the advertisement banner, the link to navigate and probability of displaying the Ads. Each time the page that contains the AdRotator control loads a new advertisement (Or the same based on Ad weight). The following is the XML file and each Ad tag gives information about the single Advertisement:

 


Pic05.JPG
 

5. Filtering Specific Ads

 

The Keyword tag in the above xml file is useful for filtering the specific type of the advertisement. The above image shows a single advertisement and belongs to the keyword (Ad Type. You can take that) Beauty. The file has 4 more advertisements in it. And there are two groups. One is Beauty and other one is Educational. We have two AdRotator controls in the content page, one at the top and other one at the bottom of the GandhiJi's Image. The top one does not do any filtering for the advertisement. The bottom one displays only the Educational Advertisement.

 

The page load event is handled for the Content page and an advertisement type filter is set to the second AdRotator control in it. The code is simple as it is just setting the Keyword filter property for the AdRotator2 control. The following is the code for it:

 

//AdRotator 01: Filter only Education ads, for Second AdRotator

protected void Page_Load(object sender, EventArgs e)

{

    AdRotator2.KeywordFilter = "Educational";

}

 

6. How Do I open the Attached Project?

  1. Download the attached zip file

  2. Extract it to a folder

  3. Open visual studio 2005

  4. Click the menu item File|Open|Web site

  5. Select the Extracted Folder

Note: The Attached solution is created in visual studio 2005. If you have latest version say yes to the conversion wizard

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Nevron Gauge for SharePoint
Become a Sponsor