日期:2014-05-17 浏览次数:20592 次
<div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick"> </asp:Timer> </ContentTemplate> </asp:UpdatePanel> </div> using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Default5 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Timer1_Tick(object sender, EventArgs e) { this.Label1.Text = System.DateTime.Now.ToString(); } }
------解决方案--------------------
定时刷新一般用js的setInterval
html标签定时刷新页面
<meta http-equiv="refresh" content="10">
<meta http-equiv="Refresh" content="60;URL=/要刷新的页面URL地址">
其中content的值是刷新页面时间间隔,单位秒
用javascript定时刷新页面
<script type="text/javascript">
setInterval("window.location.reload()",5000);
//或者
//setTimeout("window.location.reload()",5000);
</script>
自动刷新也是可以控制的...
javascript控制启动和停止自动刷新
var refresh = setTimeout("window.location.reload()", 2000);
<input type=button value=停止刷新 onclick="clearTimeout(refresh)"><br>
<input type=button value=继续刷新 onclick="refresh=setTimeout('window.location.reload()', 2000)">
------解决方案--------------------
首先在ASP.Net创建两个WebForm页,分别命名为Default1,Default2。下面给出代码清单:
//Default1.aspx
<%@ Page Language="C#" Debug="true" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="Default1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html Xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/Javascript">
var XmlHttp;
function createXmlHttpRequest()
{
if (window.XmlHttpRequest)
{
XmlHttp = new XmlHttpRequest();
}
else if (window.ActiveXObject)