Using the AdRotator control in asp.net (turn)

Source: Internet
Author: User
Tags filter border color relative
The asp.net| control uses the AdRotator control in ASP.net

Ads in asp.net can be displayed at any time by using the AdRotator server control that ASP.net carries. In this article, we'll look at two examples that use this control to display ads on one page.

There are several steps to using the AdRotator server control:

First step

Create an XML file that contains the details of the advertisement, such as Art008_ads.xml, which contains the following elements:

imageurl-contains the URL that will be displayed, either an absolute path or a relative path relative to the page that displays the advertisement.
navigateurl-contains the URL of the target Web site. (Note: Before the beta version, this element was called TargetUrl and now changed).
alternatetext-contains some text that is displayed as a hint when the mouse moves over the image. In other words, this is the text of the ALT element in the advertisement image.
keyword-This optional element contains the category that the advertisement belongs to. This allows all categories of ads to be in the same XML, and then filters the ads on a given page using the KeywordFilter property in the AdRotator control.
impressions-points to the relative cost of advertising.

One thing that is particularly noteworthy when creating an ad file is that it is case-sensitive. Therefore, the included elements should be spelled correctly, for example: you should use <Ad> instead of <ad>.

With the above details, we will create the ad XML file. The following XML file contains information that displays two ad banners:

<Advertisements>
<Ad>
<ImageUrl>/articles/demo/art008_demo1.gif</ImageUrl>
<NavigateUrl>http://www.dotnet101.com</NavigateUrl>
<alternatetext>go to. net101--Test 1</alternatetext>
<Keyword>Category1</Keyword>
<Impressions>10</Impressions>
</Ad>
<Ad>
<ImageUrl>/articles/demo/art008_demo2.gif</ImageUrl>
<NavigateUrl>http://www.dotnet101.com</NavigateUrl>
<alternatetext>go to. net101--Test 2</alternatetext>
<Keyword>Category1</Keyword>
<Impressions>10</Impressions>
</Ad>
<Ad>
<ImageUrl>/articles/demo/art008_demo3.gif</ImageUrl>
<NavigateUrl>http://www.dotnet101.com</NavigateUrl>
<alternatetext>go to. net101--Test 3</alternatetext>
<Keyword>Category2</Keyword>
<Impressions>10</Impressions>
</Ad>
</Advertisements>

Second Step

Create a AdRotator server control in the ASP.net page to connect the ad XML file to this control. Use the following server control tags to complete:

<body>
<asp:adrotator advertisementfile= "Art008_ads.xml" runat= "Server" bordercolor= "#000000" borderwidth= "1" ></ Asp:adrotator>
</body>

Http://www.dotnet101.com/articles/demo/art008_demo1.aspx here for a demo.
The AdvertisementFile attribute indicates that the advertisement file must refer to the AdRotator control in order to display the image. Because the KeywordFilter property is not set, you will see all three ad images appear randomly when you refresh the page.

To change the appearance of the ad image on the page, you can also set other properties for the AdRotator control. Here are some of the important properties:

AdvertisementFile: XML containing advertising information
BorderColor: Sets the border color for the advertisement, such as bordercolor= "#000000" to set the boundary to black
BorderWidth: Boundary width, Unit is pixel, such as borderwidth= "1"
CssClass: A font class from a CSS file or inline STYLE element, such as cssclass= "Clsads"
Height: Advertisement image altitude, Unit is pixel
KeywordFilter: Filter The advertising category, as seen in the example above
Target: The destination window for the URL when clicking on the ad. such as target= "_new", every time the ad image is clicked will produce a new window. "_top" is the default value
Width: The breadth of the advertising image, in pixels

The KeywordFilter property of a AdRotator control can filter a specific category of advertisements. In the following example, you will see only the first two images belonging to the "Category1". The example also combines some of the properties defined in the table:

<body>
<asp:adrotator
Advertisementfile= "Art008_ads.xml"
Keywordfilter= "Category1"
runat= "Server"
Bordercolor= "#000000"
Borderwidth= "1"
height= "60"
Width= "468"
target= "_new"
>
</asp:adRotator>
</body>

The sample output from the above AdRotator control in the browser is this:

<a href= "http://www.dotnet101.com" target= "_new" ></a>

Http://www.dotnet101.com/articles/downloads/art008_source.zip Download Sample Code,
Http://www.dotnet101.com/articles/demo/art008_demo1.aspx demonstrates viewing effects.


Related Article

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.