简体   繁体   中英

ASP Update Panel Not Working

I Have the following ASP Panel

<asp:UpdatePanel ID = "UpdatePanel1" runat = "server">
      <ContentTemplate>
            <asp:TextBox ID="txtNumber" runat="server" ToolTip="The Assignment's Number" ValidationGroup="updateAssignment" AutoPostBack="True" ontextchanged="txtNumber_TextChanged"></asp:TextBox>

      </ContentTemplate>
</asp:UpdatePanel>

The Script Manager is also present but the page is still doing a postback. The thing is in other pages it does not happen. I tried adding a trigger to the update panel with the control being the textbox but it still does a Postback. Please Help me Out.

First of all, serverside code not client side code. The textchanged event is much different then js onchange event. This code fires when you lose focus. You need to set autopostback to true on the textbox but include it as a trigger:

 <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="TextBox1" AutoPostBack="true" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
        </ContentTemplate>
        <Triggers>
        <asp:AsyncPostBackTrigger ControlID="TextBox1" />
        </Triggers>
        </asp:UpdatePanel>

As you noticed just setting the textbox to Autopostback=true will not work, outside of the UpdatePanel it will cause a postback. However, if wrap it around an updatepanel and specify AsyncPostBackTrigger and assign the ControlID to the textbox in question it will work for you. I have just tested this in chrome and IE and it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM