views:

132

answers:

1

How do I add an auto-refresh feature based on the value of a GET parameter?

For example, http://localhost/myPage.aspx?refresh=5 would auto-refresh the page every 5 minutes.

NOTE: A VB code example is preferred.

+1  A: 

Here is one way to do it - an alternative would be to to use javascript to force a refresh or get just the content you need, but this should work fine for a simple full-page refresh.

The following code should be added to the OnLoad handler of the page you want to refresh.

Dim secondsToRefresh As Integer
If Integer.TryParse(Request.QueryString("refresh"), secondsToRefresh) Then
    secondsToRefresh *= 60
    Page.Header.Controls.Add(New HtmlMeta() With {.HttpEquiv = "Refresh", .Content = secondsToRefresh.ToString()})
End If

Please note that I'm really a C# guy at heart, as such this VB.NET code is untested.

Chris Shouts
The syntax isn't quite right for declaring the HtmlMeta() object. I created the object, assigned the parameters, and then called .Add().Thank you!
Steven