拉了一个ScriptManager 在拉UpdatePane 在UpdatePane里面放一个Ajax控件Timer,设置时间间隔1000,在放个Label1  ,页面代码为:

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ 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">
<asp:ScriptManager id="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel id="UpdatePanel1" runat="server">
<contenttemplate><asp:Label id="Label1" runat="server" Text="Label"></asp:Label>
<asp:Timer id="Timer1" runat="server" OnTick="Timer1_Tick" Interval="1000"></asp:Timer>
</contenttemplate>
</asp:UpdatePanel>


</form>
</body>
</html>


后台代码为:

using System;
using System.Data;
using System.Configuration;
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;
using System.Web.Services.Description;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Timer1_Tick(object sender, EventArgs e)
{

this.Label1.Text = DateTime.Now.ToString();
}
}



 

问题解决了 原来是要在在web.config中的system.web配置节中添加

<httpHandlers>
<add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>



 posted on 2011-11-01 16:58  纳米程序员  阅读(836)  评论(0编辑  收藏  举报