blog

Home / DeveloperSection / Blogs / AdRotator in ASP.NET

AdRotator in ASP.NET

priyanka kushwaha2188 18-Feb-2015

In this blog, I’m explaining about AdRotator in ASP.Net

 

The AdRotator control presents ad images that, when clicked, navigate to a new web location. Each time the page is loaded into the browser, an ad is randomly selected from a predefined list.

Attributes                                                   Description

ImageURL                                           The URL of the image to display.

NavigateURL                                      The web location to navigate to when the image is clicked.

                                                                   If NavigateUrl is not set, the image is not clickable.

AlternateText                                     The text to display if the image is unavailable.

Keyword                                               The category of the ad, which can be used to filter for                                                                                   specific ads.

Impressions                                         This display rates in percent of the hits.

NOTE: All attributes are optional.

1.  To create ad list as an XML file.

2.Create an ad element inside the Advertisements element for each ad that you want to include in the ad list and then save the file.

<?xmlversion="1.0"encoding="utf-8" ?>
<Advertisements>
  <Ad>
    <ImageUrl>~/images/A.jpg</ImageUrl>
    <width>40px </width>
    <height>50px</height>
 <NavigateUrl>http://www.pastelspace.com/image_detail.php?id=1228</NavigateUrl>
  
    <AlternateText>DotNetCurry Home Page</AlternateText>
    <Impressions>40</Impressions>
    <Keyword>small1</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>~/images/B.jpg</ImageUrl>
   <width>40px </width>
    <height>50px</height>
    <NavigateUrl>http://www.pastelspace.com/image_detail.php?id=1034</NavigateUrl>
    <AlternateText>DotNetCurry Home Page</AlternateText>
    <Impressions>40</Impressions>
    <Keyword>small2</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>~/images/C.jpg</ImageUrl>
    <width>40px</width>
    <height>50px</height>
    <NavigateUrl>http://www.dotnetcurry.com</NavigateUrl>
    <AlternateText>DotNetCurry Home Page</AlternateText>
    <Impressions>40</Impressions>
    <Keyword>small</Keyword>
  </Ad>
</Advertisements> 

2.    Create a AdRotatorFIle.aspx

(Rotate Ads without Refreshing the page using AdRotator and ASP.NET Ajax)

<%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="AdRotator.aspx.cs"Inherits="AdRotatorProject.AdRotator"%>
 
<!DOCTYPEhtml>
 
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
    <title></title>
</head>
<body>
    <formid="form1"runat="server">
         <divstyle="width: 100%;">
            <asp:ScriptManagerID="ScriptManager1"runat="server"/>
            <asp:TimerID="Timer1"Interval="2000"runat="server"/>
            <asp:UpdatePanelID="up1"runat="server">
                <Triggers>
                    <asp:AsyncPostBackTriggerControlID="Timer1"EventName="Tick"/>
                </Triggers>
                <ContentTemplate>
                    <asp:AdRotator
                        ID="AdRotator1"
                        AdvertisementFile="~/AdRotator.xml"
                        runat="server"Target="_top"Width="500px"/>
               </ContentTemplate>
            </asp:UpdatePanel>
        </div>
 
    </form>
</body>
</html>
Output:

AdRotator in ASP.NETAdRotator in ASP.NET

 

 


Updated 18-Feb-2015

Leave Comment

Comments

Liked By