Solved

Refresh page every coouple minutes

Posted on 2011-02-17
5
1,466 Views
Last Modified: 2012-05-11
I need to refresh my aspx page every couple of minutes.  i found some code behind that does what I want but how do i call it automatically to refresh.  I have a datagrtid on the page that i want to refresh with new records ervery couple minutes. I can call it via a link button to refresh but how can it do it automatically or where do I put the refresh command.
Public Sub refreshpage()
        FillGrid()

        Dim meta As New HtmlMeta
        Dim HEAD As HtmlHead = DirectCast(Page.Header, HtmlHead)
        meta.HttpEquiv = "refresh"
        meta.Content = "2"
        HEAD.Controls.Add(meta)
    End Sub

Open in new window

0
Comment
Question by:kdeutsch
5 Comments
 
LVL 34

Expert Comment

by:Paul MacDonald
ID: 34916969
Rather than the codebehind, put a meta refresh tag in the page itself:
     <meta http-equiv="refresh" content="600">
...where 600 is the number of seconds between refreshes.

Make sure this is a view-only page or you'll piss people off.
0
 
LVL 23

Expert Comment

by:Rajkumar Gs
ID: 34917048
Altenative way.
I got this code, somewhere from net

<!-- Codes by Quackit.com --><html><head><script type="text/JavaScript"><!--function timedRefresh(timeoutPeriod) { setTimeout("location.reload(true);",timeoutPeriod);}//   --></script></head><body onload="JavaScript:timedRefresh(5000);"><p>This page will refresh every 5 seconds. This is because we're using the 'onload' event to call our function. We are passing in the value '5000', which equals 5 seconds.</p><p>But hey, try not to annoy your users too much with unnecessary page refreshes every few seconds!</p></body></html>


0
 
LVL 8

Accepted Solution

by:
TheMozz earned 350 total points
ID: 34917193
asp.net has a neat little timer control for just this purpose:
http://ajax.net-tutorials.com/controls/timer-control/
0
 
LVL 8

Expert Comment

by:TheMozz
ID: 34917201
Forgot to mention the timer is completely controllable from code behind as well, so it can be enabled/disabled, and the interval can be changed as desired in the code behind.
0
 

Author Closing Comment

by:kdeutsch
ID: 34917766
This is the best way to refresh only my gridview and not all the page.  Thanks
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question