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:-
01 | <? xml version = "1.0" encoding = "utf-8" ?> |
04 | < ImageUrl >images/1.jpg</ ImageUrl > |
09 | < Impressions >20</ Impressions > |
10 | < Keyword >flowers</ Keyword > |
13 | < ImageUrl >images/2.jpg</ ImageUrl > |
18 | < Impressions >20</ Impressions > |
19 | < Keyword >flowers</ Keyword > |
22 | < ImageUrl >images/3.jpg</ ImageUrl > |
27 | < Impressions >10</ Impressions > |
28 | < Keyword >flowers</ Keyword > |
31 | < ImageUrl >images/4.jpg</ ImageUrl > |
36 | < Impressions >10</ Impressions > |
37 | < Keyword >flowers</ Keyword > |
Page Design View:-
01 | <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> |
10 | < form id = "form1" runat = "server" > |
12 | < table width = "900px" align = "center" > |
13 | < tr >< td >< h2 >Example Of AD Rotator</ h2 ></ td ></ tr > |
16 | < asp:AdRotator ID = "AdRotator1" Target = "_blank" runat = "server" BorderColor = "#33CC33" BorderStyle = "Dotted" BorderWidth = "1px" AdvertisementFile = "XMLFile.xml" Height = "500px" Width = "900px" /> |