Selection of Ads using AdRotator Control at Run Time
You can advertise the Ads onrotating basis in your website. Microsoft is providing the AdRotator Control to pickthe Ad in random basis using XML file. Same controls can use even for the mobilephones. 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 firstof Ad of below in xml or you can give your own images stored in your folder.
NavigateUrl This is the URLyou 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 thekeyword to filter the adds.
Impressions This is thenumber 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.
<?xmlversion="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>Ican 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>Buywhatever you want in amazon.com</AlternateText>
<Keywod>books,articles</Keywo
d >>
<Impressions>50</Impressions>
</Ad>
<Ad>
<ImageUrl>Images/Graphics.</ImageUrl>
<NavgateUrl>http://www.nwoods.com/GO/dotnet.htm</NavgateUrl>
<AlternateText>Buildinteractive graphics with Go.Net</AlternateText>
<Keywod>Graphic</Keywod>
<Impressions>50</Impressions>
</Ad>
</Advertiements>
The Creation of Ads using AdRotation control ispretty easy.
1. Open Asp.Net Web Application
2. Drag the AdRotator control from the WebFormsin Tool box and drop in your aspx page.
3. Save the above xml into xml file
4. Go to the properties of AdRotator control andgive 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 behaviorof AdRotator control.
The image of the ad will be different in size. Soyou need to take control of size of the AdRotator control. The OnAdCreated eventhappens after the ad to be rendered. So you knows what is the ImageUrl in theOnAdCreated event. You can make the changes for height and width of theAdRotator control depending upon the size of the image. You see the differentsize image Ads by using the AdRotator control and program for OnAdCreated eventbelow.



privatevoid AdRotator1_AdCreated(objectsender, 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")
{
style="font-family:Arial;font-size:x-small;">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 therequired folder according to your advertisements. Hope you feel it's very easyto create Ads using AdRotator control after reading this article. Give any suggestionsyou have to me at rosireddyr@yahoo.com.












No comments yet... Be the first to leave a reply!