0

I have a Asp.Net web form (aspx) which contains a TextBox:

<div id="field">
   <asp:TextBox Id="Name" runat="server" MaxLength="50"/>
</div>    

I am making a jQuery ajax call after typing characters in the TextBox which returns a list of Names from the database.

$("#field input[id*='Name']").on("input", function(e) {
    $.ajax({
        url: my_WebAPI_url,
        type: 'Get',
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        async: true,
        success: function (result) {
                 console.log(result);
        }
    });
 }

After clicking on the TextBox or typing the characters for the first time, the TextBox loses its focus. I have to click on the TextBox again, and then it works fine without losing focus.

How to make the TextBox not lose focus after clicking on it for the first time?

DevP
  • 75
  • 2
  • 11
  • It sounds like you have something else on your page causing this. Impossible to tell without seeing the rest of the code. – JuanR Aug 27 '21 at 06:06

1 Answers1

0

You can go over there for your reference

https://www.aspsnippets.com/Articles/Populate-jQuery-AutoComplete-TextBox-from-Database-using-Web-Service-in-ASPNet.aspx

How do you automatically set the focus to a textbox when a web page loads?

Otherwise you also do in your page load Code file

txtname.Focus();

    or

// inside page_load 
Page.Form.DefaultFocus = Yourpage.FindControl("txtname").ClientID;