UpdatePanel控件也是Ajax里用得最多的控件之一,UpdatePanel控件是用来局部更新网页上的内容,网页上要局部更新的内容必须放在UpdatePanel控件里,他必须和上一次说的ScriptManager控件一起使用。现在来看UpdatePanel的属性
| 属性 | 说明 | 
| ChildrenAsTriggers | 当UpdateMode属性为Conditional时,UpdatePanel中的子控件的异步回送是否会引发UpdatePanle的更新。 | 
| RenderMode | 表示UpdatePanel最终呈现的HTML元素。Block(默认)表示<div>,Inline表示<span> | 
| UpdateMode | 表示UpdatePanel的更新模式,有两个选项:Always和Conditional。Always是不管有没有Trigger,其他控件都将更新该UpdatePanel,Conditional表示只有当前UpdatePanel的Trigger,或ChildrenAsTriggers属性为true时当前UpdatePanel中控件引发的异步回送或者整页回送,或是服务器端调用Update()方法才会引发更新该UpdatePanel。 | 
 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">
<head runat="server"> <title>Untitled Page</title>
    <title>Untitled Page</title> <style type="text/css">
    <style type="text/css"> body { background-attachment:fixed;
         body { background-attachment:fixed; 
              
               background-image:url(Blue hills.jpg);
                background-image:url(Blue hills.jpg); }
                } 
                 .style1
         .style1 {
         { background-position:top center;
                background-position:top center; }
         } 
          
          </style>
    </style>
 </head>
</head> <body  onload="oSpan.className=‘style1‘" >
<body  onload="oSpan.className=‘style1‘" > <form id="form1" runat="server">
    <form id="form1" runat="server"> <span style="font-size:14; width:250;" ID="oSpan"
    <span style="font-size:14; width:250;" ID="oSpan" onmouseover="this.className=‘style2‘" onmouseout="this.className=‘style1‘"></span>
        onmouseover="this.className=‘style2‘" onmouseout="this.className=‘style1‘"></span> <div>
        <div> <asp:ScriptManager ID="ScriptManager1"     runat="server">
            <asp:ScriptManager ID="ScriptManager1"     runat="server">     </asp:ScriptManager>
              </asp:ScriptManager> </div>
        </div> 
            <asp:UpdatePanel ID="uid"  runat="server">
        <asp:UpdatePanel ID="uid"  runat="server"> 
         <ContentTemplate>
            <ContentTemplate> 
             <div >
                <div > <asp:Button ID="Button1" runat="server" Text="异步回送" OnClick="Button1_Click1" />  
                    <asp:Button ID="Button1" runat="server" Text="异步回送" OnClick="Button1_Click1" />   <asp:Button ID="Button2" runat="server" Text="整页回送" OnClick="Button2_Click" /><br />
                    <asp:Button ID="Button2" runat="server" Text="整页回送" OnClick="Button2_Click" /><br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="197px">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="197px"> <Columns>
                        <Columns> <asp:BoundField DataField="au_lname" FooterText="aaaa" HeaderText="au_lname" />
                            <asp:BoundField DataField="au_lname" FooterText="aaaa" HeaderText="au_lname" /> </Columns>
                        </Columns> </asp:GridView>
                    </asp:GridView> <br />
                    <br /> <asp:Label ID="Label1" runat="server" Text="当前时间" Font-Bold="True" Font-Size="Large"></asp:Label>
                   <asp:Label ID="Label1" runat="server" Text="当前时间" Font-Bold="True" Font-Size="Large"></asp:Label> </div>
                  </div> </ContentTemplate>
            </ContentTemplate> <Triggers>
            <Triggers> <asp:AsyncPostBackTrigger    ControlID="Button1" />
                <asp:AsyncPostBackTrigger    ControlID="Button1" /> <asp:PostBackTrigger  ControlID="Button2" />
                <asp:PostBackTrigger  ControlID="Button2" /> </Triggers>
            </Triggers> 
               </asp:UpdatePanel>
        </asp:UpdatePanel> <div id="div1" >
          <div id="div1" >  </div>
               </div> 
         
         </form>
    </form> </body>
</body> </html>
</html>
里面包含了一个Triggers,里面第一个属性AsyncPostBackTrigger指定Button1实现异步更新,而PostBackTrigger
指定Button2实现整页更新。
.CS代码为:
 protected void Button1_Click1(object sender, EventArgs e)
 protected void Button1_Click1(object sender, EventArgs e) {
    { 
   SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=;database=pubs");
        SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=;database=pubs"); string sql1 = "select top 5 au_lname from authors ";
        string sql1 = "select top 5 au_lname from authors "; SqlDataAdapter myAdapter = new SqlDataAdapter(sql1, conn);
        SqlDataAdapter myAdapter = new SqlDataAdapter(sql1, conn); DataSet ds = new DataSet();
        DataSet ds = new DataSet(); myAdapter.Fill(ds, "bieminG");
        myAdapter.Fill(ds, "bieminG"); //来自web service的dataset,这里随便一个ds就可以;
        //来自web service的dataset,这里随便一个ds就可以; this.GridView1.DataSource = ds.Tables["bieminG"].DefaultView; ;
        this.GridView1.DataSource = ds.Tables["bieminG"].DefaultView; ; this.GridView1.DataBind(); //数据绑定
        this.GridView1.DataBind(); //数据绑定 }
    } protected void Button2_Click(object sender, EventArgs e)
    protected void Button2_Click(object sender, EventArgs e) {
    { this.Label1.Text = "11111";
        this.Label1.Text = "11111"; }
    }
Button1实现一个数据集的异步更新,BUTTON2就是一般的赋值了。看看是不是很简单呀!呵呵! 
原文:http://www.cnblogs.com/lsgsanxiao/p/4257380.html