AdRotator. aspx: 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 code is as follows: |
Copy code |
|
<Asp: AdRotator ID = "AdRotator1" runat = "server" AdvertisementFile = "~ /XMLFile. xml "/> |
Code for generating an advertisement
| The code is as follows: |
Copy code |
|
AdRotator. aspx. cs
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. .";
}
} |
Xml document format
| The code is as follows: |
Copy code |
|
<? Xml version = "1.0" encoding = "UTF-8"?>
<Advertisements>
<Ad>
<ImageUrl> image path (local) </ImageUrl>
<NavigateUrl> image connection </NavigateUrl>
<AlternateText> prompt when the mouse is placed </AlternateText>
<Keyword> keywords </Keyword>
<Impressions> priority </Impressions>
</Ad>
<Ad>
<ImageUrl> image path (local) </ImageUrl>
<NavigateUrl> image connection </NavigateUrl>
<AlternateText> prompt when the mouse is placed </AlternateText>
<Keyword> keywords </Keyword>
<Impressions> priority </Impressions>
</Ad>
<Ad>
<ImageUrl> image path (local) </ImageUrl>
<NavigateUrl> image connection </NavigateUrl>
<AlternateText> prompt when the mouse is placed </AlternateText>
<Keyword> keywords </Keyword>
<Impressions> priority </Impressions>
</Ad>
</Advertisements> |
Note xml
AdvertisementFile: XML containing advertisement information
BorderColor: set the boundary color for the advertisement. For example, BorderColor = "#000000" sets 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.