updatepannel是asp.net中ajax技术实现的依托,有了它我们才可以轻松实现异步传送和刷新。
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel runat="server">
<ContentTemplate> Block hello world.
<hr />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server" RenderMode="Inline">
<ContentTemplate> hello world!</ContentTemplate>
</asp:UpdatePanel>
renderMode:在客户端呈现方式。默认为Block以div方式呈现,Inline :以<span></span>标签展示。
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always">
<ContentTemplate > <%= DateTime.Now.Second %>
<asp:Button runat="server" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
<hr />
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate > <%= DateTime.Now.Second%>
<asp:Button ID="Button1" runat="server" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
updatemode :触发更新方式。Always:只要有回发就更新;conditional:控件内部触发(手动更新)。
运行结果:点击下面button两个时间都更新,点击上面button只有上面时间更新。
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
Code
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Always">
<ContentTemplate>
<%= DateTime.Now.Second%><asp:Button ID="Button1" runat="server" Text="Button" /></ContentTemplate>
</asp:UpdatePanel>
<hr />
<asp:UpdatePanel ID="UpdatePanel2" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
<ContentTemplate>
<%= DateTime.Now.Second %>
<asp:Button ID="Button2" runat="server" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
ChildrenAsTriggers:与 updatemode 功能一样都是控制更新方式,但ChildrenAsTriggers属性指定本控件内部控件是否引发回送,而updatemode属性指定本控件更新方式。注意当 updatemode 为“always”时 ChildrenAsTriggers不能为False,否则抛出异常。
运行结果:点上面button 和 点下面button效果相同都是上面时间更新。