Solved

Refresh page every coouple minutes

Posted on 2011-02-17
5
1,459 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 33

Expert Comment

by:paulmacd
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now