How To Use ADRotator In ASP.NET

How To Use ADRotator In ASP.NET

In this tutorial i will explain how to use ADRotator in ASP.NET.AdRotator control randomly selects image files from a list, which is specified in an external XML File.AdRotator control in ASP.NET is extremely used when it comes to randomly displaying advertisements on your site.AdRotator needs a Advertisement file to display images.

Following standard XML elements that are commonly used in the advertisement file.

Element Element Description
Advertisements Encloses the advertisement file
Ad Delineates separate ad
ImageUrl The image that will be displayed
NavigateUrl The link that will be followed when the user clicks the ad
AlternateText The text that will be displayed instead of the picture if it cannot be displayed
Keyword Keyword identifying a group of advertisements. This is used for filtering
Impressions The number indicating how often an advertisement will appear
Height Height of the image to be displayed
Width Width of the image to be displayed

Advertisement File Structure:-

<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
  <Ad>
    <ImageUrl>images/1.jpg</ImageUrl>
    <NavigateUrl>http://www.google.co.in</NavigateUrl>
    <AlternateText>
     Text 1
    </AlternateText>
    <Impressions>20</Impressions>
    <Keyword>flowers</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>images/2.jpg</ImageUrl>
    <NavigateUrl>http://www.google.co.in</NavigateUrl>
    <AlternateText>
      Text 2
    </AlternateText>
    <Impressions>20</Impressions>
    <Keyword>flowers</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>images/3.jpg</ImageUrl>
    <NavigateUrl>http://www.google.co.in</NavigateUrl>
    <AlternateText>
      Text 3
    </AlternateText>
    <Impressions>10</Impressions>
    <Keyword>flowers</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>images/4.jpg</ImageUrl>
    <NavigateUrl>http://www.google.co.in</NavigateUrl>
    <AlternateText>
      Text 4
    </AlternateText>
    <Impressions>10</Impressions>
    <Keyword>flowers</Keyword>
  </Ad>
</Advertisements>

Page Design View:-

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

<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table width="900px" align="center">
    <tr><td><h2>Example Of AD Rotator</h2></td></tr>
    <tr>
    <td>
    <asp:AdRotator ID="AdRotator1" Target="_blank"  runat="server" BorderColor="#33CC33" BorderStyle="Dotted" BorderWidth="1px" AdvertisementFile="XMLFile.xml" Height="500px" Width="900px" />
    </td>
    </tr>
    </table>
    </div>
    </form>
</body>
</html>

One thought on “How To Use ADRotator In ASP.NET

  1. Pingback: How to use AdRotator in ASP.NET C# Without Refreshing Page Using AJAXHighTechnology

Comments are closed.