开发者

The best way to refresh my .aspx site with a Timer in C#?

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

M开发者_开发百科y 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?


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.


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.


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.


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);
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜