How to create independent update panels?

As far as I understand UpdatePanels, they should be void separately, i.e. The trigger of one UpdatePanel should not touch the controls of another panel. It really works for controls outside of any UpdatePanels, however those that are inside ANY UpdatePanel are affected by running any 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";
    }

"Nothing should appear, but" Should not appear "appears :( Can someone help me understand what causes this behavior?

+3
source share
1 answer

Now I see this, I forgot to put the attribute UpdateMode = "Conditional" in UpdatePanels.

Work 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>
+3
source

Source: https://habr.com/ru/post/1729066/


All Articles