C# 页面定时刷新

Big鹏 2008-12-07 09:40:34

首页代码如下,我想每隔5秒刷新一次,用AJAX控件timer不好用,只能用JS,没用过JS,所以特此请教,解决分全给!
新手,请给出在哪加入语句,谢谢!
<head runat="server">
<title>无标题页</title>

</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<b>
<font color="#000099" size="5" >全部设备列表</font>
</b>
</center>
<hr color=blue width="800"></hr>

</div>
<center>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="5000">
</asp:Timer>

<table width="90%">
<tr valign="top">
<td>
<asp:GridView ID="gvInfo" runat="server" AutoGenerateColumns="False" Width="90%" CellPadding="3" AllowPaging="True" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" PageSize="2" EmptyDataText="无可显示数据。">
<Columns>

<asp:BoundField DataField="sysName" HeaderText="设备名称">
<ItemStyle HorizontalAlign="Center" Width="6%" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="deviceOnlineStatus" HeaderText="设备在线状态">
<ItemStyle HorizontalAlign="Center" Width="6%" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>

<asp:BoundField DataField="ResourceType" HeaderText="设备类型">
<ItemStyle HorizontalAlign="Center" Width="6%" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="ipAddress" HeaderText="IP地址" >
<ItemStyle HorizontalAlign="Center" Width="6%" />
<HeaderStyle HorizontalAlign="Center" />
</asp:BoundField>

</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" BorderColor="White" ForeColor="Black" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<HeaderStyle BackColor="Desktop" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
<PagerSettings Visible="False" />
<EmptyDataRowStyle BackColor="#E7E7FF" BorderStyle="None" ForeColor="Black" />
</asp:GridView>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</center>
</form>
</body>
</html>

...全文
527 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
niitnanfeng 2008-12-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 dingjian2008 的回复:]
<meta http-equiv="refresh" content="1; url=要跳转页面的网址">
content="" 中的值说明了经过多少秒后页面将跳转
[/Quote]
我也是那么用的,还有种就是用timer,其他的就不会了。
flyjimi 2008-12-07
  • 打赏
  • 举报
回复
[Quote=引用楼主 mupengzhi 的帖子:]
HTML code
首页代码如下,我想每隔5秒刷新一次,用AJAX控件timer不好用,只能用JS,没用过JS,所以特此请教,解决分全给!
新手,请给出在哪加入语句,谢谢!
<head runat="server">
<title>无标题页</title>

</head>
<body>
<form id="form1" runat="server">
<div>
<center>
<b>
<font color="#000099" size="5" >全部设备列表</font>
</b>
</center>
<hr color=blue widt…
[/Quote]

Timer控件挺好用啊,是不是你没有用对。你的OnTick事件没有处理吗?

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="lblTimer" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>



后台cs:

protected void Timer1_Tick(object sender, EventArgs e)
{
lblTimer.Text = DateTime.Now.ToString();
}
风骑士之怒 2008-12-07
  • 打赏
  • 举报
回复
Timer为什么不好用呢?局部定时刷新比全页刷新要好
mengxj85 2008-12-07
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 oec2003 的回复:]
//1秒钟执行一次函数1
window.setInterval("函數1",1000);

//延迟1秒钟执行函数2
window.setTiemout("函數2",1000);

所以要使用setInterval 第二个参数为时间
[/Quote]
顶,这样子好些
chinaxc 2008-12-07
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 oec2003 的回复:]
//1秒钟执行一次函数1
window.setInterval("函數1",1000);

//延迟1秒钟执行函数2
window.setTiemout("函數2",1000);

所以要使用setInterval 第二个参数为时间
[/Quote]
顶楼上一下。
oec2003 2008-12-07
  • 打赏
  • 举报
回复
//1秒钟执行一次函数1
window.setInterval("函數1",1000);

//延迟1秒钟执行函数2
window.setTiemout("函數2",1000);

所以要使用setInterval 第二个参数为时间
jiang_jiajia10 2008-12-07
  • 打赏
  • 举报
回复

<meta http-equiv="Refresh" content="1000;URL=...">
放在<head></head>标记内,
content="1000;URL=...
指.每秒定时刷新 内容为URL地址的页面

这个也可以
jiang_jiajia10 2008-12-07
  • 打赏
  • 举报
回复

<script>
var hwd;
var intSec = 60;
function reHandle()
{
if(intSec==0)
window.location.reload();
else
{
intSec--;

}

hwd = setTimeout(reHandle,1000);
}
reHandle();

</script>


你不会是需要这个吧
分享大哥 2008-12-07
  • 打赏
  • 举报
回复


<!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>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>js实现定时自动刷新功能</title>
</head>
<body>
<input type="button" value="reflesh" onclick="reflesh();"/>
<select id="times">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
</select>

<script>
var t = document.getElementById("times");
function reflesh()
{
alert("出发刷新操作!"+t.value);
document.location.reload();
}
setTimeout("reflesh()",t.value*1000);//每10秒钟刷新一次

</script>

</body>

</html>

dingjian2008 2008-12-07
  • 打赏
  • 举报
回复
<meta http-equiv="refresh" content="1; url=要跳转页面的网址">
  content="" 中的值说明了经过多少秒后页面将跳转
dingjian2008 2008-12-07
  • 打赏
  • 举报
回复
可使用settimeout(func,3000)
walkghost 2008-12-07
  • 打赏
  • 举报
回复
我猜楼主要的是这个代码(每秒钟刷新一次本页面)

<script>
setInterval("startRequest();",1000);//最后一个参数是时间间隔,自己该,单位毫秒
function startRequest()
{
window.location=this.location.href;
}
</script>

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧