[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Refresh page every coouple minutes

Posted on 2011-02-17
5
Medium Priority
?
1,486 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 1400 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Integration Management Part 2
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month18 days, 7 hours left to enroll

830 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