1. always :如果将UpdateMode属性设为"always",则每次发生页面回发的时候,该UpdatePanel都会刷新。这里的页面回发包括由其他UpdatePanel里的控件或不在UpdatePanel里的控件产生的回发。接着昨天的例子稍做一下改动:
< ContentTemplate >
< asp:Label ID ="lblTime" runat ="server" ></ asp:Label >< br />
< asp:Button ID ="btnShowTime" runat ="server" Text ="ShowTime" OnClick ="btnShowTime_Click" />
</ ContentTemplate >
</ asp:UpdatePanel >
< asp:UpdatePanel ID ="up2" runat ="server" UpdateMode ="always" >
< ContentTemplate >
always UpdatePanel:
< asp:Label ID ="lblAlwaysTime" runat ="server" ></ asp:Label >
</ ContentTemplate >
</ asp:UpdatePanel >
CodeFile:
{
lblTime.Text = DateTime.Now.ToString();
lblAlwaysTime.Text = DateTime.Now.ToString();
}
此时如果点击"ShowTime"按钮,两个UpdatePanel里的Label会同时更新,但如果将第二个UpdatePanel的UpdateMode设为conditional,她里面的Label就不会更新了。
2.conditional:若UpdateMode被设为conditional,则该UpdatePanel会在下列情况被刷新:
(1) 由触发器引起的刷新,如下所示:
< ContentTemplate >
always UpdatePanel:
< asp:Label ID ="lblAlwaysTime" runat ="server" ></ asp:Label >
</ ContentTemplate >
< Triggers >
< asp:AsyncPostBackTrigger ControlID ="btnShowTime" EventName ="Click" />
</ Triggers >
</ asp:UpdatePanel >
通过在UpdatePanel里设置触发器可以指定特定的按钮来刷新该UpdatePanel.上例中就给UpdatePanel设置了一个触发器,该触发器关联的控件是"btnShowTime",关联的事件是 "Click"。一个UpdatePanel可以设置多个触发器,关于触发器更深一步的知识我想以后会慢慢了解。
(2) 调用UpdatePanel的Update()方法:
{
lblTime.Text = DateTime.Now.ToString();
lblAlwaysTime.Text = DateTime.Now.ToString();
up2.Update();
}
(3) 当该UpdatePanel在其他UpdatePanel里面,并且父容器更新的时候:
< ContentTemplate >
< asp:Label ID ="lblTime" runat ="server" ></ asp:Label >< br />
< asp:Button ID ="btnShowTime" runat ="server" Text ="ShowTime" OnClick ="btnShowTime_Click" />
< asp:UpdatePanel ID ="up2" runat ="server" UpdateMode ="conditional" >
< ContentTemplate >
always UpdatePanel:
< asp:Label ID ="lblAlwaysTime" runat ="server" ></ asp:Label >
</ ContentTemplate >
</ asp:UpdatePanel >
</ ContentTemplate >
</ asp:UpdatePanel >
(4) 当 ChildrenAsTriggers 属性为true,UpdatePanel 内的控件产生回发时,其实昨天的例子就和这种情况差不多。因为默认情况下ChildrenAsTriggers的值为true ,可以省略,此是UpdateMode不管为always还是conditional效果是一样的。
注意:如果ChildrenAsTriggers设为false,则UpdateMode的值必须设为conditional,否则就会抛出异常。默认情况下UpdateMode的值为always。