tags:

views:

247

answers:

6

I am using asp.net to develop a website, and I want one of my web pages to refresh every 5 seconds when requested; how can I achieve that?

+4  A: 

Can you add a meta tag to the page's header?

From wikipedia:

Place inside to refresh page after 5 seconds:

<meta http-equiv="refresh" content="5" />

Redirect to http://example.com/ after 5 seconds:

<meta http-equiv="refresh" content="5;url=http://example.com/" />

Redirect to http://example.com/ immediately:

<meta http-equiv="refresh" content="0;url=http://example.com/" />

Also see w3schools

ongle
+2  A: 

Here is the tag for the meta refresh:

<meta http-equiv="refresh" content="5" />
Kevin
+2  A: 

Like ongle, I would suggest:

<meta http-equiv="refresh" content="5">
NoahD
+5  A: 

It should be noted that if your page is a largeish one, people on slow connections may never finish downloading the page before it refreshes.

If it is a large page and this is a concern, consider using JavaScript.

Placing this before the closing </body> tag should do the trick:

<script>setTimeout('window.location.href = window.location.href', 5000);</script>
ceejayoz
+1 This is a very valid point and I have encountered this situation before.
ongle
+1  A: 

Given that much of your page may not change, you may want to consider an AJAX panel for that, given that ASP.NET supports it.

Check out the tutorial

mike
+1  A: 

You could just use a meta tag or javascript as other suggested, but be careful when doing that. If you do it wrong you can break your viewstate. A better option might be to use the timer control and do a postback from there.

Joel Coehoorn
+1 Another very good point in cases where view state is an issue.
ongle