Tuesday, July 19, 2011

[ASP.Net] - AdRotator Control, AdvertisementFile and AdType Filter

1. Introduction

AdRotator control is useful for displaying the advertisements. This control acts as a placeholder for the image and the image is actually a link to the advertised website. 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 when the image is clicked.


2. About the Sample

The sample two pages. The main page has a link to the Content page and content page has a Go Back link to the main page. The content page is a copy paste about Mahatma Gandhi taken from the wiki page. This page has two AdRotator controls. Have a look at the below illustration:

Ad Banner and Advertisement Info XML file


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 educates the control about the advertisement details.

The below screen shot shows the main page:



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



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 same or 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.




4. The XML file

The XML file supplies the advertisement banner, the link to navigate and the 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). Below is the XML file and each Ad tag give information about the single Advertisement:




5. Filtering Specific Ads

Keyword tag in the above XML file is useful to filter the specific type of the advertisement. The above image shows Single advertisement and belongs to the keyword (Ad Type. You can take that) Beauty. The file has 4 more Advertisement in it. And there are two groups. One is Beauty and another one is Educational. We have two Adrotator control in the content page, one at the top and another one at the bottom of the GandhiJi’s Image. The top one does not do any filtering for the advertisement. 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 just setting the Keyword filter property for the AdRotator2 control. Below 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

Source Code : Download

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

1 comment:

  1. Hi,

    I was reading your article and I would like to appreciate you for making it very simple and understandable. This article gives me a basic idea of AdRotator Control in Asp.Net and it helped me a lot. Thanks for sharing with us. Check out this link too its also having nice post with wonderful explanation on AdRotator control....

    AdRotator Control in ASP.Net

    Thank you very much for your precious post!!

    ReplyDelete

Leave your comment(s) here.

Like this site? Tell it to your Firend :)