<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="Timer.index" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="Label2" runat="server" Text="不刷新"></asp:Label>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="10000" OnTick="Timer1_Tick">
</asp:Timer>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Timer
{
public partial class index : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label2.Text = "页创建在" + DateTime.Now.ToLongTimeString();
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = "刷新在" + DateTime.Now.ToLongTimeString();
}
}
}
搭建在服务器IIS上,在服务器本地浏览时候能刷新时间, 而到客户端浏览时就不刷新时间了? 请求高人帮忙解决
------解决方案--------------------
当然,服务器端使用Timer刷新界面是无效的。因为这些更新根本不会传送到客户端去。
你得使用js的timer。
------解决方案--------------------
既然页面这么简单,那么贴出从你的“客户端”浏览器上得到的html源代码来!
------解决方案--------------------
AJAX提供Timer控件实现时间计时提示功能
//每隔一秒触发一次Timer1_Tick事件
protected void Timer1_Tick(object sender, EventArgs e)
{
this.Label1.Text = System.DateTime.Now.ToString();
SqlDataReader sdr1 = this.ExceRead("select * from tb_memo ");
while (sdr1.Read())
{
this.Label2.Text = sdr1["alerttime"].ToString();
if (this.Label1.Text == sdr1["alerttime"].ToString())
{
this.Label2.Text = sdr1["subject"].ToString();
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "", "var MSG1 = new PopBubble('短消息提示:','" + this.Label2.Text + "'); MSG1.show();", true);
}
}
sdr1.Close();
}
//显示系统时间
protected void Page_Load(object sender, EventArgs e)
{
string date;
date = System.DateTime.Now.ToShortDateString() + " " + this.ddlhour.SelectedItem.Text + ":" + this.TxtMinute.Text + ":" + this.TxtSecond.Text;
this.Label2.Text = date;
}
//添加相关数据到数据库
protected void ImgQueDing_Click(object sender, ImageClickEventArgs e)
{
if (this.TxtSubject.Text.Length > 20)