MS AJAX 配置 之(ScriptManager & UpdatePanel )

1.UpdatePanel内部的控件引起的回发,来更新当前UpdatePanel内部的控件内容:
   注意:此时的ScriptManager的EnablePartialRendering属性应设为true。
            UpdatePanel的UpdateMode属性应设为Always。
            ChildAsTrigger属性应设为true。

2.UpdatePanel控件外部的控件引起的回发,来异步更新UpdatePanel内部的内容:
   a.在Page_Load方法中用ScriptManager1.RegisterAsyncPostBackControl() 来注册一下要实现异步更新的控件。
       如:ScriptManager1.RegisterAsyncPostBackControl(this.Button2);
   b.用触发器来实现。
       (1).选中要进行局部更新的UpdatePanel控件。
       (2).在其属性页中点击Triggers集合属性右边的小按钮。
       (3).在弹出的对话框中,的成员列表中添加一个AsyncPostBackTriggers成员。
       (4).指定AsyncPostBackTriggers成员的ControlID和EventName,即引发异步回送的控件的ID和该控件的事件。

3.两个UpdatePanel控件,其中一个UpdatePanel内的控件引发两个UpdatePanel控件的同时刷新。
      注意:将UpdatePanel1和UpdatePanel2两个控件的的UpdateMode属性设为"Always"

4.两个UpdatePanel控件,其中一个UpdatePanel内的控件引发当前的UpdatePanel控件的刷新,而另一个不刷新。
      注意:要把UpdatePanel1和UpdatePanel2两个控件的UpdateMode属性设为“Conditional”

5.两个UpdatePanel控件,其中一个UpdatePanel内的控件引发另一个UpdatePanel控件的刷新,而本身不刷新。
      注意:(1)要把UpdatePanel1和UpdatePanel2两个控件的UpdateMode属性设为“Conditional”;
                (2)把UpdatePanel1和UpdatePanel2的ChildrenAsTriggers属性设为false
                (3)在UpdatePanel2控件中加入一个触发器,触发源设到UpdatePanel1控件内的Button1的Click事件上。

6.两个嵌套的UpdatePanel控件,外部的UpdatePanel内的控件回发引发二者同时更新
      注意:需要把两个UpdatePanel控件的UpdateMode都设为Conditional;

7.两个嵌套的UpdatePanel控件,内部的UpdatePanel内的控件回发引发二者同时更新
      注意:(1)需要把两个UpdatePanel控件的UpdateMode都设为Conditional;
                 (2)还需要为外部UpdatePanel控件加入一个触发器,触发源指定为Button1控件的Click事件上

8.两个嵌套的UpdatePanel控件,外部的UpdatePanel内的控件回发只引发内部控件的更新
     注意 : (1)需要把两个UpdatePanel控件的UpdateMode都设为Conditional;
                (2)把外部UpdatePanel的ChildrenAsTriggers属性设为false
                (3)还需要为内部UpdatePanel控件加入一个触发器,触发源指定为Button1控件的Click事件上

9.母版页中使用UpdatePanel控件
   A.内容页面中的UpdatePanel内的控件引起回发,只更新当前内容页面的内容。
        注意 : 将两个内容页面内的两个UpdatePanel控件的UpdateMode设为Conditional,ChildrenAsTrigger设为True。
   B.在内容页面中的按钮引起回发,更新母版页中的信息。
        如 : Label l1 = (Label)Master.FindControl("Label1");
                  l1.Text = DateTime.Now.ToString();
   C.在母版页中的按钮引起回发,更新指定内容页的信息。
        如 : protected void Page_Load(object sender, EventArgs e)
               {
                     ScriptManager1.RegisterAsyncPostBackControl(this .Button1);
               }

               protected void Button1_Click(object sender, EventArgs e)
               {
                    Label l1=(Label) this.ContentPlaceHolder1.FindControl("Lable1");
                    l1.Text = DateTime.Now.ToString();
                    Label l2 = (Label)this.ContentPlaceHolder2.FindControl("Lable2");
                    l2.Text = DateTime.Now.ToString();
               }

原文地址:https://www.cnblogs.com/rongxiaoya/p/2667430.html