Focus lost on partial postback with UserControls inside UpdatePanel

前端 未结 1 949
深忆病人
深忆病人 2021-01-22 23:45

I have a bunch of user controls on a form inside an AJAX UpdatePanel, containing a couple of controls including a TextBox.

Each of these usercontrols makes up a field on

相关标签:
1条回答
  • 2021-01-23 00:36

    Ok, I think your problem is that you are including everything inside the updatepanel, my approach would be to use updatepanels only for the controls that need to be updated (maybe you would need more than one), the updatepanels would need have UpdateMode=Conditional and triggered only by the control that affects the controls inside, the control that does the postback should be outside of the updatepanel, I'm posting an example that I've already tested and works fine.

    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>
        <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />
        <asp:TextBox ID="TextBox2" runat="server" AutoPostBack="True" 
                        ontextchanged="TextBox2_TextChanged"></asp:TextBox>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                </ContentTemplate>
                <Triggers>
                <asp:AsyncPostBackTrigger ControlID="TextBox2" />
                </Triggers>
            </asp:UpdatePanel>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
            <br />
            <asp:TextBox ID="TextBox4" runat="server" AutoPostBack="True" 
                ontextchanged="TextBox4_TextChanged"></asp:TextBox>
            <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
                </ContentTemplate>
                <Triggers>
                <asp:AsyncPostBackTrigger ControlID="TextBox4" />
                </Triggers>
            </asp:UpdatePanel>
            <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
    

    As you can guess TextBox2 updates Label1 and Textbox4 updates Label2.

    0 讨论(0)
提交回复
热议问题