CODEDIGEST
Home » CodeDigest
Search
 

Technologies
 

Change Advertisement in ASP.Net AdRotator Control Without Page Refresh at Regular Interval
Submitted By Satheesh Babu B
On 12/3/2009 6:59:30 AM
Tags: AJAX,CodeDigest  

Change Advertisement in ASP.Net AdRotator Control Without Page Refresh at Regular Interval

 

The following sample code uses AdRotator and UpdatePanel control to change the ads after regular interval using Timer control.

<asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:AdRotator ID="AdRotator1" AdvertisementFile="~/Books.xml" runat="server" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
        </Triggers>
    </asp:UpdatePanel>
    <asp:Timer ID="Timer1" Interval="1000" runat="server">
    </asp:Timer>

Books.xml

<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
  <Ad>
    <ImageUrl>~/Advertisement/Packt/ASP.NET MVC 1.0.jpg</ImageUrl>
    <NavigateUrl>http://www.packtpub.com/asp-net-model-view-controller-1-0-quickly/book/mid/160309vtu36d</NavigateUrl>
    <AlternateText>ASP.NET MVC 1.0 Quickly</AlternateText>

  </Ad>
  <Ad>
    <ImageUrl>~/Advertisement/Packt/ASP.NET Social Networking.jpg</ImageUrl>
    <NavigateUrl>http://www.packtpub.com/expert-guide-for-social-networking-with-asp-.net-3.5/book/mid/160309xotsdi</NavigateUrl>
    <AlternateText>ASP.NET 3.5 Social Networking</AlternateText>

  </Ad>
  <Ad>
    <ImageUrl>~/Advertisement/Packt/ASP.NET-Architecture--Desi.gif</ImageUrl>
    <NavigateUrl>http://www.packtpub.com/application-architecture-and-design-for-asp-.net-3.5/book/mid/140109h5cpa8</NavigateUrl>
    <AlternateText>ASP.NET 3.5 Application Architecture</AlternateText>
  </Ad> 
</Advertisements>
 

The Timer control's Tick event will get raised every 1000 ms as specified in Interval Property. Since, we specified the Tick event as asynchronous trigger for the UpdatePanel control there will be a async postback which will cause the ad to be changed.

Happy Coding!!

Do you have a working code that can be used by anyone? Submit it here. It may help someone in the community!!

Recent Codes
  • View All Codes..