OnAdCreated event : AdRotator « ASP.net Controls « ASP.NET Tutorial






<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="AdTest" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
          <asp:AdRotator id="AdRotator1" 
                         runat="server" 
                         Target="_blank" 
                         AdvertisementFile="ads.xml" 
                         OnAdCreated="AdRotator1_AdCreated"></asp:AdRotator>
        <br />
        <br />
      <asp:HyperLink id="lnkBanner" runat="server">HyperLink</asp:HyperLink>
    </div>
    </form>
</body>
</html>

File: Default.aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class AdTest : System.Web.UI.Page
{
  protected void AdRotator1_AdCreated(object sender, AdCreatedEventArgs e)
  {
    lnkBanner.NavigateUrl = e.NavigateUrl;

    lnkBanner.Text = "Click here for information about our sponsor: ";
    lnkBanner.Text += e.AlternateText;
  }
}

File: ads.xml

<?xml version="1.0" encoding="utf-8" ?> 
<Advertisements>
  <Ad>
    <ImageUrl>a.gif</ImageUrl>
    <NavigateUrl>http://www.a.com</NavigateUrl>
    <AlternateText>A</AlternateText>
    <Impressions>20</Impressions>
    <Keyword>books</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>j.gif</ImageUrl>
    <NavigateUrl>http://www.j.com</NavigateUrl>
    <AlternateText>J</AlternateText>
    <Impressions>20</Impressions>
    <Keyword>Java</Keyword>
  </Ad>
</Advertisements>








3.28.AdRotator
3.28.1.AdRotator randomly display different advertisements in a page
3.28.2.AdRotator for displaying your ad (C#)
3.28.3.OnAdCreated event
3.28.4.Storing Advertisements in an XML File
3.28.5.Storing Advertisements in a Database Table
3.28.6.Using the AdRotator control as a banner ad