ASPSnippets

Alerts
Get notified when a new article is published.

Name
 
Email

Your email will always be private and will not be shared.

Follow us on twitter.
 
Refresh or Reload part of page periodically at regular intervals in ASP.Net
Author Name: Mudassar Khan Published Date: July 01, 2009
Filed Under :
ASP.Net
Views: 4645

This article will described how to refresh a part of page periodically in ASP.Net Web applications without using AJAX or JavaScript in a very simple way.

 

Concept

The first question that comes in mind is how?

So the answer is IFRAMES and META Tags make a great combination and thus help us achieve the same in a simple manner in just 2 steps. The main advantage of this approach is that it will refresh the part in the Iframe and not the whole page thus giving an AJAX effect without using AJAX or Timers.

 

Step 1: Adding Iframe

You will first need to add an Iframe to the page at any location that you prefer to be refreshed on regular basis or periodic refresh. As shown below

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Update part of page periodically</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        This is the Main Page

        <br /><br /><br /><br />

        <iframe id = "frame1" src = "refresh.aspx" frameborder = "0"

            style="width: 493px;height: 295px" >

        </iframe>

    </div>

    </form>

</body>

</html>

 

You will notice above I have added an Iframe and set the src property to the page called refresh.aspx which will be refreshed periodically. That’s it we are half done let’s move to Step 2.

 

     

Step 2: Adding Meta Tag

 

Step 2 is also fairly simple you will need to add the following meta tag to the head section of the page

 

<meta http-equiv="Refresh" content="5" />

 

The above tag will refresh the page every 5 seconds For more information on how this works and how to set it dynamically from code behind refer my article

Reload, Refresh and Redirect Pages using Meta Tags in ASP.Net

 

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Page to be Refreshed</title>

    <meta http-equiv="Refresh" content="5" />

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:Label ID="lblTime" runat="server" Text=""></asp:Label>

        <asp:GridView ID="GridView1" runat="server">

        </asp:GridView>

    </div>

    </form>

</body>

</html>

 

You will notice I have added the meta tag to the page and set the interval to 5 seconds. I have placed an ASP.Net GridView Control so that my data is refreshed at regular intervals

That’s it we are done now run the page with the Iframe in browser and see it refresh the content periodically


Refresh Part of page peridically in ASP.Net without using AJAX or JavaScript

The source is available for download in VB.Net and C#. Try it yourself.

UpdatePartPeriodically.zip (4.40 kb)


If you like this article, help us grow by bookmarking this page on any social bookmarking site.
Bookmark and Share Page copy protected against web site content infringement by Copyscape

Related Articles

Comments

Add Comments

You can add your comment about this article using the form below. Make sure you provide a valid email address
else you won't be notified when the author replies to your comment

Please note that all comments are moderated and will be deleted if they are
  • Not relavant to the article
  • Spam
  • Advertising campaigns or links to other sites
  • Abusive content.
There is no need to add BR tags. Simply press enter for new line

Name*  
Email*
Comment*  
Security code
Security code