使用 C# 中的计时器刷新 .aspx 网站的最佳方法是什么?
我有一个 default.aspx 页面,需要每 10 秒刷新一次。
到目前为止我的解决方案是一个javascript函数,但它只适用于Firefox而不是IE。
我正在寻找一种方法来处理 default.aspx.cs 页面中的刷新机制,使用某种计时器。
有什么好的简单建议/提示或解决方案可以引导我走向正确的方向吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需在页面标题中使用
标记来指示自动刷新:
如果您需要将某些信息(可能已更改)传回页面,则应仅使用 JavaScript 刷新方法服务器。
Just use a
<meta>
tag in your page header to indicate automatic refresh: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.
ms ajax 工具箱中包含一个计时器。添加一个 ScriptManager,将要刷新的内容放入 UpdatePanel 中,然后添加 ajax 计时器。
然后将为您生成适当的跨浏览器脚本。
您可以在此处查看快速教程 我如何使用aspnet ajax计时器控件
还有其他更复杂的技术可能更有效,但这会给你几分钟的工作带来好的结果。
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.
我认为
元刷新
就是您正在寻找的内容您的情况将是
编辑
由于其他用户指出正确,每 10 秒完全刷新一次,这不是一个很好的方法。我同意他们的观点,并且我也建议采用不同的方法,可能基于 ajax 或 comet。
I think that
Meta refresh
is what you're looking forIn your case would be
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.
我已经使用 jquery 成功刷新页面,它也可以在 IE 中工作。
I've used jquery to successfully refresh a page and it works in IE also.