AdRotator for displaying your ad (C#) : AdRotator « ASP.net Controls « ASP.NET Tutorial






File: MainAds.xml

<?xml version="1.0" encoding="utf-8" ?> 
<Advertisements>

  <Ad>
    <ImageUrl>yourImage.gif</ImageUrl>
    <NavigateUrl>http://www.java2s.com</NavigateUrl>
    <AlternateText>Java2s.com</AlternateText>
    <Impressions>1</Impressions>
  </Ad>

</Advertisements>


File: Default.aspx

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.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="Ads" runat="server" 
     Target="_blank" AdvertisementFile="~/MainAds.xml" OnAdCreated="Ads_AdCreated" />
        <br />
        <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 AdRotatorTest : System.Web.UI.Page
{
    protected void Ads_AdCreated(object sender, AdCreatedEventArgs e)
    {
        lnkBanner.NavigateUrl = e.NavigateUrl;
        lnkBanner.Text = "Click here for information about our sponsor: ";
        lnkBanner.Text += e.AlternateText;
    }
}








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