<!DOCTYPE Html PUBLIC "-//W3C//DTD XHtml 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xHtml11.dtd">
<html XMLns="http://www.w3.org/1999/xHtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<ASP:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server">
</ASP:ScriptManager>
<br />
<ASP:updatepanel id="UpdatePanel1" UpdateMode="conditional" runat="server"><ContentTemplate>
<asp:TextBox id="TextBox1" runat="server" ></asp:TextBox> <asp:LinkButton id="LinkButton1" runat="server" >LinkButton</ASP:LinkButton>
</ContentTemplate>
<Triggers>
<ASP:AsyncPostBackTrigger ControlID="LinkButton1" />
</Triggers>
</ASP:updatepanel>
<ASP:UpdatePanel ID="UpdatePanel2" RenderMode="block" UpdateMode="always" runat="server">
<ContentTemplate>
<asp:TextBox ID="TextBox2" runat="server"></ASP:TextBox>
<asp:LinkButton ID="LinkButton2" runat="server" >LinkButton</ASP:LinkButton>
</ContentTemplate>
</ASP:UpdatePanel>
<br />
<div>
<br />
<ASP:updateprogress id="UpdateProgress1" runat="server"><ProgressTemplate>
Please waiting, retrIEving data from server
</ProgressTemplate>
</ASP:updateprogress>
</div>
</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;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(1000);
TextBox1.Text = DateTime.Now.ToLongTimeString();
TextBox2.Text = TextBox1.Text;
string JS = "alert('ok button1 clicked!')";
Microsoft.Web.UI.ScriptManager.RegisterStartupScript(UpdatePanel2, this.GetType(), "btn1clicked", JS, true);
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(900);
TextBox2.Text = DateTime.Now.ToLongTimeString();
TextBox1.Text = TextBox2.Text;
string JS = "alert('ok button 2 clicked!')";
Microsoft.Web.UI.ScriptManager.RegisterStartupScript(UpdatePanel2, this.GetType(), "btn2clicked", JS, true);
}
} BTW,我在使用時發現一個問題,不知道是個Bug還是我使用不當,我在調試中發現UpdatePanel.IsInPartialRendering的值始終是false!希望有高人指點一下:)。
http://www.cnblogs.com/dajianshi/archive/2006/11/20/565524.Html