Kinyanjui Kamau
Kinyanjui Kamau

Reputation: 1986

ASP.NET Webforms updatepanel textbox only works on lost focus on text changed

I have this webforms application that is giving me trouble understanding what I am doing wrong. I basically want that when a user changes the value of a textbox, it triggers an OnTextChanged event whenever there is any change in text. No button is involved.

What is happening is that when I click outside of the textbox after entering text, the event gets triggered which I do not want.

How to fix this? I have checked online for solutions but can't find any. The textbox id is Barcode.

<asp:PlaceHolder runat="server" ID="ErrorMessage" Visible="false">
   <p class="text-danger">
      <asp:Literal runat="server" ID="FailureText" />
   </p>
</asp:PlaceHolder>
<div class="form-group">
   <asp:Label runat="server" AssociatedControlID="Barcode" CssClass="col-md-2 control-label">Barcode</asp:Label>
   <div class="col-md-10">
      <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
         <ContentTemplate>
            <asp:TextBox runat="server" ID="Barcode" CssClass="form-control" AutoPostBack="true" OnTextChanged="Barcode_TextChanged" />
            <p class="text-danger">
               <%: BarCodeNotFound %>
            </p>
         </ContentTemplate>
      </asp:UpdatePanel>
   </div>
</div>
<div class="form-group">
   <asp:Label runat="server" AssociatedControlID="TotalScanCount" CssClass="col-md-2 control-label">Scan Count</asp:Label>
   <div class="col-md-10">
      <asp:TextBox runat="server" ID="TotalScanCount" CssClass="form-control" />
   </div>
</div>

On the .cs side:

protected void Barcode_TextChanged(object sender, EventArgs e)
{
  //bla bla
}

Upvotes: 0

Views: 20

Answers (0)

Related Questions