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

天涯浪子 提交于 2019-12-22 08:14:35

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.




回答4:


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


来源:https://stackoverflow.com/questions/3023424/the-best-way-to-refresh-my-aspx-site-with-a-timer-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!