Wednesday, April 22, 2009

How to use ASP.NET AdRotator Control




Please visit my new Web Site https://coderstechzone.com



In recent days rising of of eCommerce, affiliation program, internet marketing, site hosting , pay per click , freelance advertising banners have played a lucrative role of primary or additional income source for many web sites. So in one senetence we can say that the AdRotator control of ASP.Net is used to display a sequence of ad images which is one of the built in ASP.Net server control. If you need to generate more ads in a single place in your web page you may think about AdRotator. Because the AdRotator feeds sequence of ads with its corresponding URL. You could use the target property within the AdRotator control for the destination page opener. If you set target='blank' then ads will be displayed in a new browser otherwise within the container page.

Since the AdRotator server control use XML file to display the ads so you have give the first look on how you can generate XML file forAdRotator. Here i will describe the format of XML:

*** Must begin and end with an tag.
*** Under tag there may be one or more tags which represents a single ad.
*** Under tag you can define the below elements:


ElementRequired?Description
<imageurl>NoImage location
<navigateurl>NoURL to link to the ad
<alternatetext>NoImage alternate text
<impressions>NoDisplay ratio based on hits

So for an example the basic syntax of an XML file looks like:

<advertisements>
<ad>
<imageurl>/Path/abc_company_logo.gif </imageurl> <navigateurl>http://abccompany.com </navigateurl>
<alternatetext>Want to share your development experience!</alternatetext>
<keyword>Cosmetics</keyword>
<impressions>3</impressions>
</ad>
<ad>
<imageurl>/Path/def_company_logo.gif</imageurl> <navigateurl>http://defcompany.com</navigateurl>
<alternatetext>Want to share your development experience!</alternatetext<
<keyword>Sunglass</keyword>
<impressions>5</impressions>
</ad>
</advertisements>


So now open a notepad paste this above code & modify it in your way & save the file in root directory with a name testadrotator.xml for testing. Now add an AdRotator control in your page. HTML code looks like:

<asp:adrotator id="firstadrotator" runat="server" advertisementfile="testadrotator.xml" borderwidth="2"/>

Now press F5 hope your Adrotator will work.

One very cool feature of AdRotator control is 'Keyword'. You can set the KeywordFilter property to show only Ads that match the keyword you specify in the XML file. Lets you have two pages one is for cosmetics & other is for sunglasses. So definitely you want to display cosmetics related ads in your cosmetics page. So you have to add the KeywordFilter="Cosmetics" in the AdRotator control like:

<asp:adrotator id="firstadrotator" runat="server" advertisementfile="testadrotator.xml" borderwidth="2" keywordfilter="Cosmetics" />

The above AdRotator will display only cosmetics Ads. So i think basic understaning is clear. Now i am looking for how we can dynamicaly generate the asp.net(C#) server side control AdRotator & change configuration xml file. To do that you have to add a Panel in your page & runtime add the control in the panel container by just 3 lines like:

AdRotator firstadrotator = new AdRotator();
// You can change dynamically xml file from here
firstadrotator.AdvertisementFile = "testadrotator.xml";
Panel1.Controls.Add(firstadrotator);


Hope now you can use the AdRotator control in your page.

3 comments:

Anonymous said...

I would like to have a series of three AdRotator images in the same page, that use the same XML, but does not allow one of the ads to appear in more than one position. Is there a way to establish a "group" of ads that rotate randomly within multiple ad spots?

For example, I may have 10 advertisers to display in three spots at a time. I want each of the three ads to be unique/not duplicated during a single rotation.

Saion Roy said...

HI Anonymous,
You raise a nice question. But i think that you can't achieve that in an easy way. You can either try to find out a free admanger control or try to build a control using javascipt.

Anonymous said...

If you use a database you can better manage the Ads in a given AdRotator. If you use XML - you need XPath to do a unique multiple AdRotators Advert - so as to select the three rows and use a given row to bind - so basically you would create an ObjectSource which uses Xpath to select the 3 Ads you want.

Want to say something?
I WOULD BE DELIGHTED TO HEAR FROM YOU

Want To Search More?
Google Search on Internet
Subscribe RSS Subscribe RSS
Article Categories
  • Asp.net
  • Gridview
  • Javascript
  • AJAX
  • Sql server
  • XML
  • CSS
  • Free Web Site Templates
  • Free Desktop Wallpapers
  • TopOfBlogs
     
    Free ASP.NET articles,C#.NET,VB.NET tutorials and Examples,Ajax,SQL Server,Javascript,Jquery,XML,GridView Articles and code examples -- by Shawpnendu Bikash