您的位置:首页 > 编程语言 > ASP

Web Server Controls->ASP.NET AdRotator Control

2007-03-27 08:40 471 查看

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:

ElementDescription
<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

PropertyDescription
AdvertisementFileThe path to the XML file that contains ad information
idA unique id for the control
KeywordFilterA filter to limit ads after categories
OnAdCreatedThe name of the function to be executed after the creation of the control, before page rendering
runatSpecifies that the control is a server control. Must be set to "server"
TargetWhere 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:




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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: