Search Forum
(53671 Postings)
Search Site/Articles

Archived Articles
712 Articles

C# Books
C# Consultants
What Is C#?
Download Compiler
Code Archive
Archived Articles
Advertise
Contribute
C# Jobs
Beginners Tutorial
C# Contractors
C# Consulting
Links
C# Manual
Contact Us
Legal

GoDiagram for .NET from Northwoods Software www.nwoods.com


 
Printable Version

Selection of Ads using AdRotator Control at Run Time
By Rosi Reddy

You can advertise the Ads on rotating basis in your website. Microsoft is providing the AdRotator Control to pick the Ad in random basis using XML file. Same controls can use even for the mobile phones. See the Xml file below. It contains the following attributes.

 ImageUrl       This is the URL of the image. You can give the image link of website like first of Ad of below in xml or you can give your own images stored in your folder.

NavigateUrl   This is the URL you want to navigate when you click on the Ad in AdRotator control.

AlternateText This is the text display, when you keep mouse on the Image.

Keyword   This is the keyword to filter the adds.

Impressions   This is the number of times the ad rotator will display the ad through it's random rotation. The total of all impressions values in the XML file may not exceed 2,048,000,000 - 1

All of these attributes are optional.

<?xml version="1.0" encoding="utf-8" ?>

<Advertiements>

<Ad>

<ImageUrl>http://www.csharphelp.com/images/dnc-box2.gif</ImageUrl>

<NavgateUrl>http://www.dotnetcharting.com/home.aspx</NavgateUrl>

<AlternateText>I can explain How to create Charts in .Net</AlternateText>

<Keywod>Chart, Graph</Keywod>

<Impressions>50</Impressions>

</Ad>

<Ad>

<ImageUrl>Images/Amazon.gif</ImageUrl>

<NavgateUrl>http://www.amazon.com/exec/obidos/subst/home/home.html/102-8864787-3504966</NavgateUrl>

<AlternateText>Buy whatever you want in amazon.com</AlternateText>

<Keywod>books, articles</Keywod>

<Impressions>50</Impressions>

</Ad>

<Ad>

<ImageUrl>Images/Graphics.</ImageUrl>

<NavgateUrl>http://www.nwoods.com/GO/dotnet.htm</NavgateUrl>

<AlternateText>Build interactive graphics with Go.Net</AlternateText>

<Keywod>Graphic</Keywod>

<Impressions>50</Impressions>

</Ad>

</Advertiements>

The Creation of Ads using AdRotation control is pretty easy.

1. Open Asp.Net Web Application

2. Drag the AdRotator control from the WebForms in Tool box and drop in your aspx page.

3. Save the above xml into xml file

4. Go to the properties of AdRotator control and give the xml path for Advertisement File property

5. Add the images to the folder as given in Xml.

6. Now you build and run the program to know the behavior of AdRotator control.

The image of the ad will be different in size. So you need to take control of size of the AdRotator control. The OnAdCreated event happens after the ad to be rendered. So you knows what is the ImageUrl in the OnAdCreated event. You can make the changes for height and width of the AdRotator control depending upon the size of the image. You see the different size image Ads by using the AdRotator control and program for OnAdCreated event below. 

 

 

private void AdRotator1_AdCreated(object sender, System.Web.UI.WebControls.AdCreatedEventArgs e)

{

if(e.ImageUrl == "Images/Amazon.gif")

{

AdRotator1.Height = 100;

AdRotator1.Width = 150;

}

else if(e.ImageUrl == "http://www.csharphelp.com/images/dnc-box2.gif")

{

AdRotator1.Height = 150;

AdRotator1.Width = 150;

}

else

{

AdRotator1.Height = 100;

AdRotator1.Width = 500;

}

}

 

Conclusion
Now you can make the changes to the xml file and load images to the required folder according to your advertisements. Hope you feel it's very easy to create Ads using AdRotator control after reading this article. Give any suggestions you have to me at rosireddyr@yahoo.com.

Source Code For Article