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 的独立刷新