<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Label" Width="164px"></asp:Label><br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</ContentTemplate>
</asp:UpdatePanel>
VS2005提供一種局部重新整理的方法,即使用UpdatePanel來實作
首先在建網站時選擇ASP.NET AJAX-Enabled Web Site,這樣在用戶端代碼會比普通網站多出<asp:ScriptManager ID="ScriptManager1" runat="server" />一句
UpdatePanel的格式為以下:
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
在 <ContentTemplate>之間可添加網站代碼,比如添加
<asp:Label ID="Label2" runat="server" Text="Label" Width="164px"></asp:Label><br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
其中Button1是對Label2進行的操作,是以要保證兩個控件都在同一個UpdatePanel,否則不能實作局部重新整理
另外注意UpdatePanel 的一個屬性 UpdateMode="Conditional",此屬性并不是一開始就有的,需要手動添加,添加此句後即可實作多個UpdatePanel 的獨立重新整理