- Back to Home »
- ASP.NET »
- ASP.NET AdRotator control changing ad without refreshing webpage
Posted by :
Sudhir Chekuri
Saturday, 5 October 2013
AdRotator control available in ASP.NET toolbox of Visual studio is used to display multiple ads on the same control.
Advertisements information has to be given in the form of xml file.
Here i have a javascript code that changes the ad in the AdRotator control for every 4 seconds.
XML source file contains data of 3 ads and every ad contains navigation url, Image Url, Alternative text.
Navigate Url is the url of the webpage to which it has to redirect with a click on the ad.
Image Url is used to display the image in AdRotator control.
Alternative text is the text message displayed when the user mouse is over the AdRotator control.
Javascript to be written in ASP.NET webform to refresh ad for every 4 seconds
<script type="text/javascript"
src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function () {
setInterval(function () {
$("#adr").load(location.href + " #adr", "" + Math.random() + "");
}, 4000);
});
</script>
------------------
ASP.NET Code to add AdRotator
<asp:AdRotator ID="adr" runat="server" AdvertisementFile="~/myadds.xml"
Target="_blank" />
--------------------
XML File code containing advertisements information which acts as a source for AdRotator control
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/images/1.jpg</ImageUrl>
<NavigateUrl>http://localhost:7352/rykonlineexam/images/1.jpg</NavigateUrl>
<AlternateText>This is online exam</AlternateText>
<Impressions>5</Impressions>
</Ad>
<Ad>
<ImageUrl>~/images/2.jpg</ImageUrl>
<NavigateUrl>http://localhost:7352/rykonlineexam/images/2.jpg</NavigateUrl>
<AlternateText>this is image2</AlternateText>
<Impressions>3</Impressions>
</Ad>
<Ad>
<ImageUrl>~/images/5.jpg</ImageUrl>
<NavigateUrl>http://localhost:7352/rykonlineexam/images/5.jpg</NavigateUrl>
<AlternateText>this is 5 image</AlternateText>
<Impressions>2</Impressions>
</Ad>
</Advertisements>
Advertisements information has to be given in the form of xml file.
Here i have a javascript code that changes the ad in the AdRotator control for every 4 seconds.
XML source file contains data of 3 ads and every ad contains navigation url, Image Url, Alternative text.
Navigate Url is the url of the webpage to which it has to redirect with a click on the ad.
Image Url is used to display the image in AdRotator control.
Alternative text is the text message displayed when the user mouse is over the AdRotator control.
Javascript to be written in ASP.NET webform to refresh ad for every 4 seconds
<script type="text/javascript"
src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(document).ready(function () {
setInterval(function () {
$("#adr").load(location.href + " #adr", "" + Math.random() + "");
}, 4000);
});
</script>
------------------
ASP.NET Code to add AdRotator
<asp:AdRotator ID="adr" runat="server" AdvertisementFile="~/myadds.xml"
Target="_blank" />
--------------------
XML File code containing advertisements information which acts as a source for AdRotator control
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/images/1.jpg</ImageUrl>
<NavigateUrl>http://localhost:7352/rykonlineexam/images/1.jpg</NavigateUrl>
<AlternateText>This is online exam</AlternateText>
<Impressions>5</Impressions>
</Ad>
<Ad>
<ImageUrl>~/images/2.jpg</ImageUrl>
<NavigateUrl>http://localhost:7352/rykonlineexam/images/2.jpg</NavigateUrl>
<AlternateText>this is image2</AlternateText>
<Impressions>3</Impressions>
</Ad>
<Ad>
<ImageUrl>~/images/5.jpg</ImageUrl>
<NavigateUrl>http://localhost:7352/rykonlineexam/images/5.jpg</NavigateUrl>
<AlternateText>this is 5 image</AlternateText>
<Impressions>2</Impressions>
</Ad>
</Advertisements>
It is really a great work and the way in which u r sharing the knowledge is excellent.
ReplyDeleteThanks for helping me to understand basic concepts. As a beginner in java programming your post help me a lot.Thanks for your informative article.Dot Net training in chennai | Dot Net training institutes in chennai | Dot Net training in velachery