How advertising controls are used:
An ad file is an XML file in which all tag attributes are analyzed and placed in the AdProperties dictionary for attribute editing.
Ads.xml
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<!--ad file is an XML file-->
<Advertisements>
<Ad>
<ImageUrl>4rwbgzby.gif</ImageUrl>
<NavigateUrl>http://www.jb51.net</NavigateUrl>
<AlternateText>Text_01</AlternateText>
<KeyWord>one</KeyWord>
<Impressions>40</Impressions>
<aniaml>i ' m using AdRotator no.1</aniaml>
</Ad>
<Ad>
<ImageUrl>banner.jpg</ImageUrl>
<NavigateUrl>http://www.jb51.net</NavigateUrl>
<AlternateText>Text_02</AlternateText>
<KeyWord>two</KeyWord>
<Impressions>40</Impressions>
<aniaml>i ' m using AdRotator no.2</aniaml>
</Ad>
<Ad>
<ImageUrl>cvtxlkw4.gif</ImageUrl>
<NavigateUrl>http://www.jb51.net</NavigateUrl>
<AlternateText>Text_03</AlternateText>
<KeyWord>three</KeyWord>
<Impressions>30</Impressions>
<aniaml>i ' m using AdRotator no.3</aniaml>
</Ad>
</Advertisements>
AdRotator.aspx.cs
Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
public partial class MyTest_advertisement:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{
}
protected void ad_created (object sender, AdCreatedEventArgs e)
{
if ((string) e.adproperties["Animal"]!= "")
Label1.Text = (string) e.adproperties["Aniaml"];
Else
Label1.Text = "N.a."
}
}
adrotator.aspx
Copy Code code as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "AdRotator.aspx.cs" inherits= "Mytest_advertisement"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>using adrotator</title>
<body>
<form id= "Form1" runat= "Server" >
<div>
<%--adrotator file--%>
<asp:adrotator id= "AdRotator1" runat= "Server"
target= "_blank"
Advertisementfile= "Ads.xml"
onadcreated= "ad_created"/>
<br/>
Animal:
<asp:label id= "Label1" runat= "Server" text= "Label" ></asp:Label>
</div>
</form>
</body>
1. Refactoring Menu: Extraction method (ctrl+r,ctrl+m) Encapsulation field (CTRL+R,CTRL+F)
2, the dictionary keyword is animal, the value into a string,
(string). adproperties["Aniaml"]