locked
How do I delay the AsyncPostBackTrigger? RRS feed

  • Question

  • User1997491293 posted

    Following is what I have written on the front end of my web page

    <div id="Div1" style="float: left;">
      <asp:UpdatePanel ID="UpdatePanel2" runat="server">
    
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="txtAN" EventName="TextChanged" />
        </Triggers>
    
        <ContentTemplate>
             <asp:TextBox ID="TextBox1" runat="server" CssClass="text_font" Height="16" Width="100" MaxLength="500"                                                  OnTextChanged="txtAN_TextChanged" AutoPostBack="true">
             </asp:TextBox>
         </ContentTemplate>
    
        </asp:UpdatePanel>
    </div>
            

    A value (Ex : 0003333) is being scanned in to this text box (TextBox1) from a QR code reader. But there is a weird delay when scanning the value from the QR code reader. First the digit 0 (zero) (which is the first digit of the given example) appears in the text box but the rest of the values (003333) appear after a few milliseconds. As soon as the first digit appears, my event (txtAN_TextChanged) gets triggered so an incorrect value is given as the input. 

    Can someone help me to solve this matter. Thanks in advance.

    Thursday, January 29, 2015 6:48 AM

Answers

  • User-271186128 posted

    Hi tharakab,

    As far as we all known, the TextChanged event doesn't fire until you tab out of the textbox (or click somewhere else on the page). From your description, we can know that after the first number input, it will trigger the textChange event. I suppose it is related to the QR code reader.

    I suggest you could add a conditional statement in the TextChanged event. Like this.

                <asp:ToolkitScriptManager ID="ToolkitScriptManager1" EnablePageMethods="true" runat="server"></asp:ToolkitScriptManager>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:TextBox ID="TextBox1" AutoPostBack="true" OnTextChanged="TextBox1_TextChanged" runat="server"></asp:TextBox>
                        <br />
                         <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="TextBox1" EventName="TextChanged" />
                    </Triggers>
                </asp:UpdatePanel>

    Code Behind:

            protected void TextBox1_TextChanged(object sender, EventArgs e)
            {
                //Check the textBox value length.
                if(TextBox1.Text.Length>3)
                {
                    Label2.Text = TextBox1.Text;
                }
            }

    Besides, you could also try to add a button into updatepanel, and use it to get the textbox value.

    Best Regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, January 30, 2015 1:44 AM