使用 C# 中的计时器刷新 .aspx 网站的最佳方法是什么?

发布于 2024-09-05 11:00:42 字数 191 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

海夕 2024-09-12 11:00:42

只需在页面标题中使用 标记来指示自动刷新:

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

如果您需要将某些信息(可能已更改)传回页面,则应仅使用 JavaScript 刷新方法服务器。

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.

如梦初醒的夏天 2024-09-12 11:00:42

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.

淡淡の花香 2024-09-12 11:00:42

我认为 元刷新 就是您正在寻找的

内容您的情况将是

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

编辑

由于其他用户指出正确,每 10 秒完全刷新一次,这不是一个很好的方法。我同意他们的观点,并且我也建议采用不同的方法,可能基于 ajax 或 comet。

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.

白衬杉格子梦 2024-09-12 11:00:42

我已经使用 jquery 成功刷新页面,它也可以在 IE 中工作。

$(document).ready(function() {
         $("#content_1").load("yourSite.aspx");
       var refreshId = setInterval(function() {
          $("#content_1").load('yourSite.aspx');
       }, 5000);
    });

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);
    });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文