Thursday 7 November 2013

How To Use the AdRotator Control in an ASP.NET Application

<html>
<head>
<title>AdRotator in ASP.NET</title>
</head>
<body>
<form id="Form1" runat="server">
<asp:AdRotator ID="AdRotator1" AdvertisementFile="AdRotator.xml"  runat="server" OnAdCreated="Navigate_URL"  target="_search" />
<h5><a href="AdRotator.xml" target="_search">View AdRotator XML Code.</a></h5>
</form>
</body>
</html>

Take one .xml file,name it as AdRotator.xml and write the following code.
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
  <Ad>
    <ImageUrl>https://www.google.com/images/srpr/logo11w.png</ImageUrl>
    <NavigateUrl>http://www.google.com</NavigateUrl>
    <AlternateText>Google</AlternateText>
    <Impressions>50</Impressions>
    <Keyword>Search</Keyword>
  </Ad>
  <Ad>
    <ImageUrl>https://www.google.co.in//logos/doodles/2013/cv-ramans-125th-birthday-5688529564729344-hp.jpg</ImageUrl>
    <NavigateUrl>http://www.google.com</NavigateUrl>
    <AlternateText>Google</AlternateText>
    <Impressions>50</Impressions>
    <Keyword>Search</Keyword>
  </Ad>
</Advertisements>


In C#.NET:
protected void Navigate_URL(object sender, AdCreatedEventArgs e)
     {
     e.NavigateUrl="http://www.Google.com" ;
     }


In VB.NET:
Protected Sub Navigate_URL(ByVal sender As Object, ByVal e As AdCreatedEventArgs) Handles Me.Load
        e.NavigateUrl = "http://www.Google.com"
    End Sub



The output of the above page as shown in the below figures.



When you run the page it shows the first figure.when you click Ctrl+F5 then the below figure will display.

No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.