ASP. NET Advertising control AdRotator usage and example

  • 2020-06-19 10:05:39
  • OfStack

adRotator. aspx, create an AdRotator server control in the ASP. NET page, and connect the AD XML file to this control. Use the following server control tags to do this

<asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/XMLFile.xml" />

The code that generates the AD

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.a.";
}
}

xml document format

<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
    <Ad>
    <ImageUrl> Image path (local) </ImageUrl>
    <NavigateUrl> The picture connection </NavigateUrl>
    <AlternateText> Mouse over the prompt </AlternateText>
    <Keyword> The keyword </Keyword>
    <Impressions> priority </Impressions>
  </Ad>
  <Ad>
    <ImageUrl> Image path (local) </ImageUrl>
    <NavigateUrl> The picture connection </NavigateUrl>
    <AlternateText> Mouse over the prompt </AlternateText>
    <Keyword> The keyword </Keyword>
    <Impressions> priority </Impressions>
  </Ad>
  <Ad>
    <ImageUrl> Image path (local) </ImageUrl>
    <NavigateUrl> The picture connection </NavigateUrl>
    <AlternateText> Mouse over the prompt </AlternateText>
    <Keyword> The keyword </Keyword>
    <Impressions> priority </Impressions>
  </Ad>
</Advertisements>

Note xml
AdvertisementFile: XML with advertising messages
BorderColor: Set the border color for ads. For example, BorderColor="#000000", set the border to black
BorderWidth: Boundary width in pixels, as in BorderWidth="1"
CssClass: Font class from CSS files or inline STYLE elements, such as CssClass="clsAds"
Height: The height in pixels of an advertising image
KeywordFilter: Filter advertising categories, as seen in the above example
Target: The target window of URL when an AD is clicked. For example, Target="_new", every time the AD image is clicked, a new window is created. "_top" is the default
Width: The width of an advertisement image in pixels
The KeywordFilter property of the AdRotator control filters ads for a specific category

Related articles: