<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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="ScriptManager" runat="server" EnablePartialRendering="true" />
<!-- Step 2: Wrap our existing code in an "UpdatePanel" -->
<asp:UpdatePanel ID="TimeStampPanel" runat="server">
<ContentTemplate>
<asp:Button ID="UpdateButton" runat="server" Text="Update" />
<asp:TextBox ID="TimeStampTextBox" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
<!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="ScriptManager" runat="server" EnablePartialRendering="true" />
<!-- Step 2: Wrap our existing code in an "UpdatePanel" -->
<asp:UpdatePanel ID="TimeStampPanel" runat="server">
<ContentTemplate>
<asp:Button ID="UpdateButton" runat="server" Text="Update" />
<asp:TextBox ID="TimeStampTextBox" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
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 Default2 : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
this.UpdateButton.Click += delegate
{
this.TimeStampTextBox.Text = DateTime.Now.ToLongTimeString();
};
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
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 Default2 : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
this.UpdateButton.Click += delegate
{
this.TimeStampTextBox.Text = DateTime.Now.ToLongTimeString();
};
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
参考
http://ajax.asp.net/docs/tutorials/IntroductionUpdatePanel.aspx