How do I make independent Update Panels?
As far as I understand UpdatePanels, they should be invalidated separately, i.e. triggerring one UpdatePanel should not touch the controls of the other panel. It does work so for controls outside of any UpdatePane开发者_开发技巧ls, however those which are inside ANY UpdatePanel are touched by triggering ANY UpdatePanel:
    <form id="form1" runat="server">
<asp:ScriptManager ID="SM1" runat="server"/>
<div>
    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
    <asp:UpdatePanel ID="update1" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdatePanel ID="update2" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>
</div>
</form>
Code behind:
        protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "Clicked 1";
        TextBox2.Text = "Shouldn't appear";
        TextBox3.Text = "Neither should this";
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox2.Text = "Clicked 2";
        TextBox1.Text = "Shouldn't appear";
        TextBox3.Text = "Neither should this";
    }
"Neither should this" does not appear, however "Shouldn't appear" appears :(. Can anybody help me understand what causes this behavior?
Now I see it, I forgot to put the UpdateMode="Conditional" attribute to the UpdatePanels.
Working code:
    <form id="form1" runat="server">
<asp:ScriptManager ID="SM1" runat="server"/>
<div>
    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
    <asp:UpdatePanel ID="update1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdatePanel ID="update2" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:Button ID="Button2" runat="server" Text="Button" onclick="Button2_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>
</div>
</form>
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论