专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Web Service

服务器Timer控件在客户端访问页面时不刷新?解决方案

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
服务器Timer控件在客户端访问页面时不刷新?
<%@ 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)
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: