Solved

Refresh page every coouple minutes

Posted on 2011-02-17
5
1,469 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Suggested Solutions

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

737 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