App_data.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="App_data.aspx.cs" Inherits="WebApplication1.App_data" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title></title> </head> <body> <form id="form1" runat="server"> <div> </div> <asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/ad.xml" OnAdCreated="AdRotator1_AdCreated" /> <br /> <br /> <strong>这节我们讲广告空间 <br /> <br /> </strong>它需要一个xml文件<br /> 这个xml文件节点参数说明:<br /> <br /> <table class="table"style="width:494px;height:147px"> <tr> <td style="width:25%"> <b>ImageUrl</b></td> <td>图片地址</td> </tr> <tr> <td style="width:25%"> <b>NavigateUrl</b> </td> </tr> </table> </form> </body> </html>
ad.xml---广告xml
<?xml version="1.0" encoding="utf-8" ?> <Advertisements> <Ad> <ImageUrl> ~/img/accent.png</ImageUrl> <NavigateUrl>http://www.baidu.com</NavigateUrl> <AlternateText>洪川医药</AlternateText> <KeyWord>医院评价</KeyWord> <Impression>50</Impression> <StartDate>6/27/07</StartDate> <EndDate>6/99/2007</EndDate> </Ad> <Ad> <ImageUrl> ~/img/accent.png</ImageUrl> <NavigateUrl>http://www.sina.com</NavigateUrl> <AlternateText>你好啊</AlternateText> <KeyWord>关键</KeyWord> <Impression>50</Impression> <StartDate>6/27/07</StartDate> <EndDate>6/99/2007</EndDate> </Ad> </Advertisements>
事件
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace WebApplication1 { public partial class App_data : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void AdRotator1_AdCreated(object sender, AdCreatedEventArgs e) { string url = e.AlternateText; string sdt = e.AdProperties["StartDate"].ToString(); string edt = e.AdProperties["EndDate"].ToString(); Response.Write(url + "开始日期是" + sdt + "结束日期" + edt); } } }
实现效果:
页面显示,图片,图片对应不同的链接;重新刷新之后,显示不同的广告,不同的图片,点击打开不同的链接。Amazing~~吼吼
时间: 2024-10-26 02:24:47