Register | Login
Thursday, August 28, 2008

Sections
  
About Us
  
Hosting Provided by Server Intellect
Partners
Downloads
  
 WWWCoder.com Resource Directory

How to use AdRotator control in ASP.Net
9/20/2005 9:55:00 AM

Adrotator control is available in ASP.Net to make the task of rotating the advertisement images in a web form quickly and easily. It also enables you to display different types of images whenever you refresh the page. Adrotator control takes the information about the images that are to be displayed from an XML file which also have many other elements in it that are used by this control.

Adrotator control is available in ASP.Net to make the task of rotating the advertisement images in a web form quickly and easily. It also enables you to display different types of images whenever you refresh the page. Adrotator control takes the information about the images that are to be displayed from an XML file which also have many other elements in it that are used by this control.

First let us have a look at a sample advertisement file that is used by the adrotator control in ASP.Net.

Let us assume that the advertisement XML file is named as advt.xml. This file might look like,

<Advertisements>

<Ad>
<ImageUrl>site1img1.jpg</ImageUrl>
<NavigateUrl>http://www.site1.com</NavigateUrl>
<AlternateText>Site1 Main</AlternateText>
<Impressions>50</Impressions>
<Keyword>Product1</Keyword>
</Ad>

<Ad>
<ImageUrl>site2img2.jpg</ImageUrl>
<NavigateUrl>http://www.site2.com</NavigateUrl>
<AlternateText>Site2 Main Page</AlternateText>
<Impressions>75</Impressions>
<Keyword>Product2</Keyword>
</Ad>

</Advertisements>

The XML file that is used for advertisements would have the root element as the <Advertisements> element. This may have many <Ad> child elements. The elements <ImageUrl>, <NavigateUrl>, <AlternateText>, <Impressions> and <Keyword> are found in the <Ad> element. These elements identify the properties of the image that is displayed using the adrotator control.

The <ImageUrl> element specifies the path to the image that is displayed using the AdRotator control. Once a user clicks the image that is displayed the user is taken to the URL specified in the <NavigateUrl> element. The <AlternateText> element holds the text that is displayed when the image is not loaded. The text in this element is also used as a ToolTip in some of the browsers. The element <Impressions> has a number as a value. This number indicates how often the image is displayed with respect to other images. The more the value of the number in this element, the more is the frequency of the image that is displayed. The sum of all the impressions in the advertisement file should not exceed 2,047,999,999. Otherwise the AdRotator will throw an runtime exception. The element <Keyword> is used to give the category of the advertisement.

You can just drag and drop a AdRotator control in the webform and set its attributes if you are using Visual Studio .Net. The code that is generated for the AdRotator control might be something as given below:

<asp:AdRotator id="AdRotator1"
   Target="_self"
   AdvertisementFile="advt.xml"
   runat="server"/>

In the above code in the HTML file you could see that the AdvertisementFile attribute of the AdRotator control has the xml file “advt.xml”. The other attributes are ‘id’ and ‘Target’. During runtime the AdRotator control uses the controls like <asp:HyperLink> and <asp:Image> to display the image in the web form page. The size of the image that is displayed is limited by the size of the AdRotator control that is found in the page. So, if you want to display larger images you need to adjust the size of the AdRotator control during design time itself.

It is possible to modify the values of the <ImageUrl>, <NavigateUrl> and <AlternateText> programmatically. For this you can use the AdCreated event. Thus by using the AdCreated event the rendering of the AdRotator control can be controlled.

<script runat="server">
Sub AdCreated_Event(sender As Object, e As AdCreatedEventArgs)
 e.NavigateUrl = "http://www.yoursite.com"  
End Sub     
</script>

Using the above script you can modify the NavigateUrl property programmatically. This even is called in the AdRotator control as given below in the HTML code for the web form.

<asp:AdRotator id="AdRotator1" runat="server"
   AdvertisementFile = "advt.xml"
   Target="_self"
   OnAdCreated="AdCreated_Event"/>

The OnAdCreated property of the AdRotator control specifies the event that is called which changes the URL to be navigated.

Thus the AdRotator control is an easy way to display and rotate advertisements and also to give preference to some advertisements by using the <Impressions> element of the advertisement XML file.

Want to stay current with the latest technology developments related to .NET. Visit Custom server controls in ASP.Net web page to get your FREE subscription now!


Page Options:
format for printing  Format for Printer
email article  Email Page
add to your favorites   Add to Favorites
How would you rate the quality of this content?
Poor - - Excellent
Comments?
Overall Rating:
Comments Left:
Left on 8/25/2008 4:27:05 PM by Anonymous
Comments: Great Exp
Left on 8/19/2008 5:02:58 AM by Anonymous
Comments: what is this images r not rotating
Left on 8/4/2008 2:46:30 AM by Anonymous
Comments: Not in an eloborated manner
No ratings available.
Left on 8/4/2008 2:45:21 AM by Anonymous
Comments: very good for begineers
Left on 6/16/2008 7:30:54 AM by Anonymous
Comments: It helped me.
Left on 6/12/2008 6:33:50 AM by Anonymous
Comments: the code is not sufficient.
santosh
Left on 6/10/2008 4:46:35 AM by Anonymous
Comments: poor
Left on 6/10/2008 4:45:45 AM by Anonymous
Comments: excellent
Left on 5/22/2008 1:32:52 AM by Anonymous
Comments: very good
Left on 5/1/2008 4:26:41 AM by Anonymous
Comments: nice
Left on 4/30/2008 5:58:36 AM by Anonymous
Comments: Very good.It is very helpful for beginners.
Left on 4/24/2008 11:10:52 PM by Anonymous
Comments: not Excellent but good
Left on 4/18/2008 4:01:26 AM by Anonymous
Comments: very nice
Left on 4/10/2008 12:53:42 AM by Anonymous
Comments: vcb
Left on 1/17/2008 1:36:05 PM by Anonymous
Comments: Good
Left on 12/26/2007 5:05:31 AM by Anonymous
Comments: what if we want the xml file to refreshed everyday ,if data is from system
No ratings available.
Left on 12/21/2007 4:49:47 AM by Anonymous
Comments: Gives detail summary

Left on 12/5/2007 12:03:11 AM by Anonymous
Comments: I need this with database when the banner is shown impression of the particular banner has to be decremented can any help me in this
Left on 10/23/2007 2:14:31 AM by Anonymous
Comments: how to use in programming. eg:for events
Left on 9/2/2007 4:41:00 AM by Anonymous
Comments: Gives clear idea about adrotator
Left on 7/1/2007 2:13:12 AM by Anonymous
Comments: this site very good
Left on 6/26/2007 10:41:40 PM by Anonymous
Comments: how can i use it in Visual studio2005
Left on 6/14/2007 6:06:53 AM by Anonymous
Comments: Nice
Left on 6/3/2007 3:09:19 PM by Anonymous
Comments: test comment
Left on 6/3/2007 3:08:43 PM by Anonymous
Comments: dfdfdfdfdd
Left on 5/28/2007 5:32:26 AM by Anonymous
Comments: How to Connect Database
No ratings available.
Left on 5/18/2007 3:46:49 AM by Anonymous
Comments: i need the full source code
Left on 5/12/2007 4:39:14 AM by Anonymous
Comments: execellent and good enough for the  beginners to understand the basic with example about adrotator. Beneyaz
Left on 5/12/2007 4:36:49 AM by Anonymous
Comments: good enough for the  beginners to understand the basic with example about adrotator
Left on 4/9/2007 12:58:57 AM by Anonymous
Comments: hi myself dipti chhatrapati . and i was so confused about this control but this article has provideed very simple and profound description regarding this control
Left on 3/28/2007 5:30:41 AM by Anonymous
Comments: good...
Left on 2/8/2007 11:26:14 AM by Anonymous
Comments: How can I add a .swf into AdRotator and assign an OnClick event
No ratings available.
Left on 12/6/2006 9:15:21 PM by Anonymous
Comments: gh
Left on 10/3/2006 10:55:43 PM by Anonymous
Comments: fine
Left on 9/3/2006 9:08:17 AM by Anonymous
Comments:
Left on 6/19/2006 10:45:43 AM by Anonymous
Comments: good stie

Left on 2/22/2006 4:17:58 AM by Anonymous
Comments: how do you create an administrator page that inserts new announcements in the xml file?
Left on 1/10/2006 7:52:58 AM by Anonymous
Comments: Excellent
Left on 10/17/2005 11:40:49 AM by Anonymous
Comments: Comments from the following blog: -:[web caboodle]:-, located at: http://blog.dannyboyd.com/archive/2005/10/17/7270.aspx
No ratings available.
  

 Latest Articles
  

 Latest News
  

 

Spotlight
Syndication

 


 


Digg This
 


DotNetNuke Platinum Benefactor

  
 

 Terms Of Use | Privacy Statement
 Copyright 2008 - Santry Technology Solutions, Box 172, Girard, PA 16417, (814) 774-0970