Asp.net 如何在指定的时间段内自动刷新网页
我正在使用asp.net开发一个网站,我希望我的一个网页在被请求时每5秒刷新一次;我怎样才能做到这一点呢?你能给页面的标题添加一个Asp.net 如何在指定的时间段内自动刷新网页,asp.net,html,dom,Asp.net,Html,Dom,我正在使用asp.net开发一个网站,我希望我的一个网页在被请求时每5秒刷新一次;我怎样才能做到这一点呢?你能给页面的标题添加一个meta标签吗 发件人: 放在里面刷新页面 5秒后: <meta http-equiv="refresh" content="5" /> <meta http-equiv="refresh" content="5;url=http://example.com/" /> 重定向到后面 5秒: <meta http-equiv="re
meta
标签吗
发件人:
放在里面刷新页面
5秒后:
<meta http-equiv="refresh" content="5" />
<meta http-equiv="refresh" content="5;url=http://example.com/" />
重定向到后面
5秒:
<meta http-equiv="refresh" content="5" />
<meta http-equiv="refresh" content="5;url=http://example.com/" />
重定向到
立即:
<meta http-equiv="refresh" content="0;url=http://example.com/" />
另请参见这里是元刷新的标签:
<meta http-equiv="refresh" content="5" />
像ongle一样,我建议:
<meta http-equiv="refresh" content="5">
需要注意的是,如果你的页面太大,连接速度慢的人可能永远无法在页面刷新之前完成下载
如果是大页面,这是一个问题,考虑使用JavaScript。< /P> 将此项放在结束标记之前应该可以完成以下操作:
<script>setTimeout('window.location.href = window.location.href', 5000);</script>
setTimeout('window.location.href=window.location.href',5000);
<>代码> 考虑到你的大部分页面可能不会改变,你可能想考虑一个Ajax面板,因为ASP.NET支持它。
检查一下您可以按照其他建议使用meta标记或javascript,但在这样做时要小心。如果操作错误,则可能会破坏viewstate。更好的选择可能是使用计时器控件并从那里回发。alo您可以在后台代码中使用此代码,如下所示:
ClientScript.RegisterStartupScript(this.GetType(), "", " setTimeout('window.location.href = window.location.href', 1000);", true);
同样值得注意的是,如果您正在执行此操作,并且有母版页,那么您需要在母版页而不是asp内容页中执行此操作
<meta http-equiv="refresh" content="5;url=http://example.com/" />
+1这是一个非常有效的观点,我以前也遇到过这种情况。+1在视图状态存在问题的情况下,这是另一个非常好的观点。我现在也在这样做,但问题是使用这种方法没有错误处理。如果页面刷新,并且页面上出现某种错误,那么它将停止,不再刷新。是否有任何方法可以通过这种方式调用错误处理,以便您可以决定继续刷新或停止友好的错误?听起来您可能应该在ajax中执行一些操作,而不是页面刷新。