Asp. NET notes the use of advertising controls _ practical skills

Source: Internet
Author: User

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"]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.