服务器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)
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
这是一种动态图形人机界面(HMI)
传统的HMI人机界面一般是采用很多ActiveX控件堆放在一个画面上,每个ActiveX控件执行一个功能(例如曲...
-
数据库存了图片路径,获取时出了问题
我有两张页面,我的图片保存在sshh文件夹中,当主页要用到图片时候,路径是对的:web1/sshh/ss.jpg
但...
-
web Service 验证方式,该如何选择?
公司要开放WEB SERVICE,看了许多发现验证方式有:使用SoapHeader传递和验证用户、使用验证票(Autho...
-
Web Service 参数问题
我有三个工程,一个是类库A,一个WebService B,一个是应用程序 C
假设A中有一个类a,B中有两个ASMX b1,b...
-
打包WebService程序
我希望能把我的WebService程序制作成安装包,安装时能够自动建立网站运行,什么打包工具可以用,谢谢了!
------解...
-
Web Service 要增加附件 怎么做?
Web Service 通信时如果要增加图片或是声音文件 要怎么做?
最后附上代码
------解决方案--------...
-
wcf开发restful的服务
那位高手知道有wcf开发restful的服务的资料、源码、视频,请告知一下,不胜感激
------解决方案-------------...
-
ws在IIS上面发布之后,运行报错
我的代码如图,我就是写了一个简单的方法测试而已
在IIS上面发布之后如图
然后我右键预览,就出这个...
-
为什么ajax的webservice的后台文件必须放在App_Code目录下?
如题。放到其他地方就会报错。
------解决方案--------------------
...
-
刚接触WEBSERVICE,有问题特来请教前辈(关于发布)
最近公司要求使用WEBSERVICE,以方便以后的扩展,因此来学习下这个,但是现在看了蛮多例...