1. Introduction to ASP’s AdRotator
ASP’s AdRotator Control is useful for showing the Ads. This control acts as a placeholder for the image and the image is actually a link to the advertised website. AdRotator control regularly changes the image display and when the user clicks the image, they navigate to the target website. To use AdRotator, we must first create the images to the external websites. Then an XML file tells the AdRotator Control which site to navigate when a user clicks the image.
2. About this ASP Example
This example has two pages. The main page has a link to the Content page and content page has a Go Back link to the main page. Content page is a copy paste of information about Mahatma Gandhi which is taken from the wiki page. This page has two AdRotator controls. Have a look at the below illustration:
Main page navigates to the content page and the content page steers back to the main page through a link kept in it. Content page displays the Ads using the AdRotator control. The AdvertisementFile property of the Adrotator control looks for the XML file, which informs the control about the Ads details. The below screen shot shows the main page:
When we click the “Here” hyperlink, ASP will navigate us to the content page where we show the Ads. The screen shot of the content page is below:
This page has the Go Back link and the link will bring us to the Main page. Also, this page has information about the Gandhi, and it displays two advertisements above and below his pictures. The XML file set to the AdvertisementFile property serves the advertisements selectively. Each time when we come to this page, we may see a different advertisement in it.
3. Images For the Ads
First, we create the banners for this example by visiting the site and taking a screenshot. Next, we create a folder called AdImages then place these images in it. Finally, we add all the images to the ASP.net project using the Add item content menu. The content of this folder is shown below:
4. XML File Feed For ASP AdRotator
The XML file stores the Ad banner along with the link to navigate & probability of displaying the Ads. Each time when user navigates to this page, the AdRotator control loads a new banner image into it based on the Ad weight set in the XML file. Below is the XML file and each Ad Tag give information about the single Ad.:
5. Filtering Specific Ad
Keyword tag in the above XML file is useful to filter a specific advertisement. The above image shows Single Ad and fits to the keyword Beauty. The file has 4 more Ads in it and can see that by downloading the example. 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 Gandhi’s Image. The top one does not do any filtering for the Ads. The AdRotator Control in the bottom picks only Educational Ads.
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?
- Download the attached zip file
- Extract it to a folder
- Open visual studio 2005
- Click the menu item File|Open|Web site
- Select the Extracted Folder
Source Code: Download from Google Drive