当前位置:编程学习 > C#/ASP.NET >>

scriptManager实现异步刷新问题

我想在label上显示每个时刻,然后我就写了这些代码:(1)页面代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="time.aspx.cs" Inherits="time" %>

<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
    Namespace="System.Web.UI" TagPrefix="asp" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick">
            </asp:Timer>
        系统时间:
            <asp:Label ID="show" runat="server" Text="Label"></asp:Label><br />
             
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>
(2).cs代码:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class time : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        show.Text = DateTime.Now.ToString();
    }

    protected void Timer1_Tick(object sender, EventArgs e)
    {
       show.Text = DateTime.Now.ToString();
    }
}
但是运行结果不对,label上显示的时间只是打开页面的时候的时间,感觉没有实现异步刷新,请问该怎么改呢? --------------------编程问答-------------------- if(!IsPostBack)
   show.Text = DateTime.Now.ToString();
--------------------编程问答-------------------- 在Page_Load事件里修改成上面code --------------------编程问答-------------------- Page_Load  事件里不用给label赋值就可以啊。 --------------------编程问答-------------------- 你启用Timer控件了吗,就是属性:Enable=true,还有设事件的时间间隔Interval=1000 --------------------编程问答-------------------- http://topic.csdn.net/u/20101214/22/c953e647-4e7a-4234-b6fa-5db8a8b38789.html
这个也是你的帖子吧。
上面人的回复你尝试了吗?
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,