Monday 23 November 2015

AdRotator control in Asp.Net

Introduction:

   I will explain here about adrotator control and how to show xml based advertisment file with using adrotator control.

Explanation:

  Adrotator control mainly used to display advertisement files in asp.net page.You can show images and text using adrotator control.You can display advertisment using xml file here i do that how to show advertisment with using xml file.



First i create xml file here:

<?xml version="1.0" encoding="utf-8" ?>
<Advertisements
 xmlns="http://schemas.microsoft.com/AspNet/AdRotator-Schedule-File">
 <Ad>
    <ImageUrl>apple.gif</ImageUrl>
    <NavigateUrl>http://www.fruitstest.com</NavigateUrl>
    <AlternateText>Apple fruit </AlternateText>
    <Impressions>50</Impressions>
    <Keyword>apple</Keyword>
 </Ad>
 <Ad>
    <ImageUrl>orange.gif</ImageUrl>
    <NavigateUrl>http://www.fruitstest.com</NavigateUrl>
    <AlternateText>Orange fruit</AlternateText>
    <Impressions>50</Impressions>
    <Keyword>orange</Keyword>
 </Ad>
 <Ad>
    <ImageUrl>Banana.gif</ImageUrl>
    <NavigateUrl>http://www.fruitstest.com</NavigateUrl>
    <AlternateText>Banana fruit</AlternateText>
    <Impressions>50</Impressions>
    <Keyword>banana</Keyword>
 </Ad>
</Advertisements>


ImageUrl:Location path of the image to use.

NavigateUrl:Redirect URL when image is clicked.

AlternateText:It has string value it is display when image is not found.

Impressions:It is numerical value it indicating how often an advertisement will appear.

Keyword:It is used for identifying a group of advertisements and it is  used for filtering.



i stored xml file with name is ads.xml.

Sample code here for how to call xml file using adrotator control with AdvertisementFile property.

Through Source code:

<asp:AdRotator id="Adrotator1" runat="server"
    AdvertisementFile="ads.xml" Target="_self">
</asp:AdRotator>

Through Code behind code:


Adrotator1.AdvertisementFile = "ads.xml.xml";


No comments:

Post a Comment