Google Brother Up

2009/02/03

Ad Rotator Simplest Example

1. Add two images called Microsoft.jpg, Google.jpg in images folder.

2. Create an XML page advt.xml by replacing { with <>

{?xml version="1.0" encoding="utf-8" ?}
{Advertisements}

  {Ad}
    {ImageUrl}~/images/Google.jpg{/ImageUrl}
    {NavigateUrl}http://www.google.com{/NavigateUrl}
    {AlternateText}Google{/AlternateText}
    {Impressions}1{/Impressions}
    {Keyword}Google{/Keyword}
  {/Ad}

  {Ad}
    {ImageUrl}~/images/Microsoft.jpg{/ImageUrl}
    {NavigateUrl}http://www.microsoft.com{/NavigateUrl}
    {AlternateText}Microsoft{/AlternateText}
    {Impressions}2{/Impressions}
    {Keyword}Microsoft{/Keyword}
  {/Ad}

{/Advertisements}

3. Create a Page called AdRotatorPage.aspx

{%@ Page Language="C#" AutoEventWireup="true" CodeFile="AdRotatorPage.aspx.cs" Inherits="AdRotatorPage" %}

{!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}Ad Rotator Example{/title}
{/head}
{body}
    {form id="form1" runat="server"}
    {div}
        {asp:AdRotator ID="adrDAL" runat="server" Target="_self" AdvertisementFile="~/advt.xml"
        Height="350px" Width="500px" /}
    {/div}{br /}
    {div}
        {asp:AdRotator ID="adrDAL2" runat="server" Target="_self" AdvertisementFile="~/advt.xml"
        Height="350px" Width="500px" OnAdCreated="adrDAL2_AdCreated" /}
    {/div}
    {/form}
{/body}
{/html}

4. Create a Page called AdRotatorPage.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 AdRotatorPage : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void adrDAL2_AdCreated(object sender, AdCreatedEventArgs e)
    {
        e.NavigateUrl = "http://vaichatt.blogspot.com";
        //e.ImageUrl = "~/images/Yahoo.jpg"; // if this image is present there in images folder
    }
}


177 unique visitors

No comments:

Drop Down List

1. http://www.janetsystems.co.uk/Articles/NetArticles/tabid/74/itemid/161/modid/449/Default.aspx