Use of the AdRotator control in ASP. NET

Source: Internet
Author: User

By using the AdRotator control carried by ASP. NET, advertisements in ASP. NET can be displayed at any time. In this article, we will see two examples, they use this control to display ads on a page.

To use the AdRotator control, follow these steps:

Create an XML file containing advertisement details, such as art008_ads.xml, which contains the following elements:

◆ ImageUrl-contains the URL of the image to be displayed, which can be an absolute path or a relative path relative to the page on which the advertisement is displayed.

◆ NavigateUrl-contains the URL of the target Web site. Note: Before beta, this element was called TargetUrl and has changed ).

◆ AlternateText-contains some text that is displayed as a prompt when the mouse moves over the image. In other words, this is the text of ALT elements in AD images.

◆ Keyword-This optional element contains the category of the advertisement. In this way, all types of ads are in the same XML, and then the ads are filtered on the given page using the Keywordfilter attribute in the AdRotator control.

◆ Impressions-indicates the relative overhead of an advertisement.

It is case-sensitive when creating an ad file. Therefore, the uppercase and lowercase letters of the contained elements should be correctly spelled. For example, they should be used instead.

With the above details, we will create an advertisement XML file. The following XML file contains information about two ad banners:

 
 
  1. ﹤Advertisements﹥   
  2. ﹤Ad﹥   
  3. ﹤ImageUrl﹥/articles/demo/art008_demo1.gif﹤/ImageUrl﹥   
  4. ﹤NavigateUrl﹥http://www.51cto.com﹤/NavigateUrl﹥   
  5. ﹤AlternateText﹥Go to .net101 -- Test 1﹤/AlternateText﹥   
  6. ﹤Keyword﹥Category1﹤/Keyword﹥   
  7. ﹤Impressions﹥10﹤/Impressions﹥   
  8. ﹤/Ad﹥   
  9. ﹤Ad﹥   
  10. ﹤ImageUrl﹥/articles/demo/art008_demo2.gif﹤/ImageUrl﹥   
  11. ﹤NavigateUrl﹥http://www.51cto.com﹤/NavigateUrl﹥   
  12. ﹤AlternateText﹥Go to .net101 -- Test 2﹤/AlternateText﹥   
  13. ﹤Keyword﹥Category1﹤/Keyword﹥   
  14. ﹤Impressions﹥10﹤/Impressions﹥   
  15. ﹤/Ad﹥   
  16. ﹤Ad﹥   
  17. ﹤ImageUrl﹥/articles/demo/art008_demo3.gif﹤/ImageUrl﹥   
  18. ﹤NavigateUrl﹥http://www.51cto.com﹤/NavigateUrl﹥   
  19. ﹤AlternateText﹥Go to .net101 -- Test 3﹤/AlternateText﹥   
  20. ﹤Keyword﹥Category2﹤/Keyword﹥   
  21. ﹤Impressions﹥10﹤/Impressions﹥   
  22. ﹤/Ad﹥   
  23. ﹤/Advertisements﹥  

Create an AdRotator Server Control on the ASP. NET page and connect the ad XML file to the control. Use the following Server Control flag to complete the process:

 
 
  1. ﹤html﹥   
  2. ﹤body﹥   
  3. ﹤asp:adRotator AdvertisementFile="art008_ads.xml" runat="server" BorderColor="#000000" BorderWidth="1"﹥﹤/asp:adRotator﹥   
  4. ﹤/body﹥   
  5. ﹤/html﹥  

The AdvertisementFile attribute indicates an ad file. to display an image, you must reference the AdRotator control. Because the KeywordFilter attribute is not set, when the page is refreshed, all three ad images are displayed randomly.

To change the appearance of the AD image on the page, you can also set other attributes of the AdRotator control. The following are some important attributes:

◆ AdvertisementFile: XML containing Advertisement Information

◆ BorderColor: Set the boundary color for the advertisement, for example, BorderColor = "#000000". Set the boundary to black.

◆ BorderWidth: Border width, in pixels, such as BorderWidth = "1"

◆ CssClass: font class from CSS files or inline STYLE elements, such as CssClass = "clsAds"

◆ Height: the Height of the AD image in pixels.

◆ KeywordFilter: Filter advertisement categories, as shown in the preceding example.

◆ Target: Click the Target window of the URL when the advertisement is clicked. For example, if Target = "_ new", a new window is generated every time an advertisement image is clicked. "_ Top" is the default value.

◆ Width: the Width of the AD image in pixels.

The KeywordFilter attribute of the AdRotator control can filter advertisements of a specific category. In the following example, you will only see the first two images belonging to "Category1. In this example, the attributes defined in some tables are combined:

 
 
  1. ﹤html﹥   
  2. ﹤body﹥   
  3. ﹤asp:adRotator   
  4. AdvertisementFile="art008_ads.xml"   
  5. KeywordFilter="Category1"   
  6. runat="server"   
  7. BorderColor="#000000"   
  8. BorderWidth="1"   
  9. Height="60"   
  10. Width="468"   
  11. Target="_new"   
  12. ﹥   
  13. ﹤/asp:adRotator﹥   
  14. ﹤/body﹥   
  15. ﹤/html﹥  

The sample output of the above AdRotator control in the browser is as follows:

<A href ="Http://www.51cto.com"Target =" _ new "> </a>

  1. Construct an XML Web Service using ASP. NET
  2. Talking about how to design the drag-and-drop ASP. NET online customer service
  3. Automatic Generation using tools for getting started with ASP. NET 2.0 localization technology
  4. Analysis of ASP. NET Unit Testing
  5. ASP. NET: all instances share a static variable.

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.