关键是将updatepanel的 UpdateMode 设置为 UpdateMode ="Conditional" 默认的话是always 所以同一个页面中的不同updatepanel 总不同时更新,觉的十分不爽,我们设置为 UpdateMode ="Conditional" ,即条件更新后,情况就不同了。
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode ="Conditional" >
<ContentTemplate>
1---<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
<asp:Button ID="Button1" runat="server" Text="Button" />接下来我们再在我们想要触发更新的updatepanel 中加入
<Triggers ><asp:AsyncPostBackTrigger ControlID ="Button2" EventName ="Click" /></Triggers>
这样的话呢,点击button时的updatepanel2才更新呦。好的问题解决了,和大家共享吧。
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode ="Conditional">
<ContentTemplate>
2---<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers ><asp:AsyncPostBackTrigger ControlID ="Button2" EventName ="Click" /></Triggers>
</asp:UpdatePanel>
<ContentTemplate>
2---<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
<Triggers ><asp:AsyncPostBackTrigger ControlID ="Button2" EventName ="Click" /></Triggers>
</asp:UpdatePanel>
本文介绍如何通过设置 ASP.NET AJAX 中 UpdatePanel 的 UpdateMode 属性为 Conditional 来实现部分页面内容按需更新,避免不必要的页面刷新。并详细展示了如何配置触发器使得特定按钮点击时仅更新指定的 UpdatePanel。
300

被折叠的 条评论
为什么被折叠?



