views:

108

answers:

4

I have a default.aspx page that needs to be refresh every 10 sec.

My solution so far is a javascript function, but it only works in Firefox and not IE.

I'm looking for a way to handle the refresh mecanism in the default.aspx.cs page instead, with some sort of Timer.

Any good simple sugestions/hints or solutions out there that can lead me in the right direction?

+3  A: 

I think that Meta refresh is what you're looking for

In your case would be

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

EDIT

As other users point correclty, full refresh each 10 seconds it's not a very nice approach. I agree with them and I suggest a different approach too, probably based on ajax or comet.

Claudio Redi
While this is the correct answer if you want the entire page refreshed, I'd discourage using it in practise as it is very disorienting for your user. Better to use ajax and update only the portion of the page which needs updating.
Iain Galloway
@Iain Galloway: 100% agree with you. Full refresh each 10 seconds would be a nightmare for user :-)
Claudio Redi
+2  A: 

I've used jquery to successfully refresh a page and it works in IE also.

$(document).ready(function() {
         $("#content_1").load("yourSite.aspx");
       var refreshId = setInterval(function() {
          $("#content_1").load('yourSite.aspx');
       }, 5000);
    });
czuroski
+1: OP probably does not need to reload the whole page. This will be more lightweight, although does require javascript.
RedFilter
I think this might be the best way since IE has a setting to disable meta refresh. But it should be set to allow it unless your site is in restricted zone.
Mikael Svenson
+3  A: 

Just use a <meta> tag in your page header to indicate automatic refresh:

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

You should only use a JavaScript refresh approach if you need to pass some information (that may have changed) back to the page on the server.

LBushkin
+3  A: 

There is a timer that is included with ms ajax in the toolbox. Add a ScriptManager, put the content you want refreshed inside an UpdatePanel and then add the ajax timer.

The appropriate cross browser scripting will then be generated for you.

You can view a quick tutorial here How do I use the aspnet ajax timer control

There are other more complex techniques which may be more efficient, but this will give you good results for a few minutes work.

James Westgate
I allready have a ScriptManager and a UpdatePanel and was looking for a Timer, so this is a perfect answer for me. It even has video tutorial.
radbyx