Web Server Controls->ASP.NET AdRotator Control

Definition and Usage

The AdRotator control is used to display a sequence of ad images.

This control uses an XML file to store the ad information. The XML file must begin and end with an <Advertisements> tag. Inside the <Advertisements> tag there may be several <Ad> tags which defines each ad.

The predefined elements inside the <Ad> tag are listed below:

Element Description
<ImageUrl> Optional. The path to the image file
<NavigateUrl> Optional. The URL to link to if the user clicks the ad
<AlternateText> Optional. An alternate text for the image
<Keyword> Optional. A category for the ad
<Impressions> Optional. The display rates in percent of the hits


Properties

Property Description
AdvertisementFile The path to the XML file that contains ad information
id A unique id for the control
KeywordFilter A filter to limit ads after categories
OnAdCreated The name of the function to be executed after the creation of the control, before page rendering
runat Specifies that the control is a server control.  Must be set to "server"
Target Where to open the URL

Examples

AdRotator

ASPX Source:

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

<html>
<body>

<form runat="server">
<asp:AdRotator AdvertisementFile="Ad1.xml"
runat="server" OnAdCreated="change_url"
target="_blank" />
</form>

<p><a href="ad1.xml" target="_blank">View XML file</a></p>

</body>
</html>


Output Result:
W3Schools Main Site

View XML file


IF you click the link "View XML file", it will shows:

- <Advertisements>
- <Ad>
  <ImageUrl>/banners/w6.gif</ImageUrl>
  <NavigateUrl>http://www.w3schools.com</NavigateUrl>
  <AlternateText>W3Schools Main Site</AlternateText>
  <Impressions>50</Impressions>
  <Keyword>elearning</Keyword>
  </Ad>
- <Ad>
  <ImageUrl>/banners/rd_xhtml.jpg</ImageUrl>
  <NavigateUrl>http://www.w3schools.com/xhtml/default.asp</NavigateUrl>
  <AlternateText>XHTML Tutorial</AlternateText>
  <Impressions>50</Impressions>
  <Keyword>XHTML</Keyword>
  </Ad>
  </Advertisements>

In this example we declare an AdRotator control in an .aspx file. Then we create an event handler for the AdCreated event, in the .aspx file, to override the value of the NavigateUrl element in the XML file.

posted on 2007-03-27 08:40  改变热爱  阅读(308)  评论(0)    收藏  举报

导航