locked
text box focus on asp.net ajax RRS feed

  • Question

  • User1122778340 posted

    Hi,

    I have a signUp form in asp.net (web form)

    I check User Name is reserved or not in text-box text changed (with ajax)

    but when user enter a key and text changed event occure,

    text box loss cursor. and when I focus on text box (in text-changed event), the cursor come to first of text box Instead of being in end of text.

    I hope that was clear :)

    Thanks alot :)

    Sunday, August 21, 2016 3:04 AM

Answers

  • User954927490 posted

    you are making an ajax call to check if username is reserved of not. focus on the textbox in the success event of that ajax call

    function testAjax(handleData) {
      $.ajax({
        url:"yoururl",  
        success:function(data) {
          // focus on textbox here
        }
      });
    }
    
    If txtboxid is an id, you need a #
    
    $('#txtboxid').focus();
    
    and if your cursor is not set at last charcher of your textbox.
    
    Below is a work around..
    
    $("#txtboxid").val($("#txtboxid").val()); 

    let me know if you still face any issue.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 21, 2016 7:11 AM

All replies

  • User954927490 posted

    you are making an ajax call to check if username is reserved of not. focus on the textbox in the success event of that ajax call

    function testAjax(handleData) {
      $.ajax({
        url:"yoururl",  
        success:function(data) {
          // focus on textbox here
        }
      });
    }
    
    If txtboxid is an id, you need a #
    
    $('#txtboxid').focus();
    
    and if your cursor is not set at last charcher of your textbox.
    
    Below is a work around..
    
    $("#txtboxid").val($("#txtboxid").val()); 

    let me know if you still face any issue.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, August 21, 2016 7:11 AM
  • User1122778340 posted

    Thanks alot.

    but what is Url?

    this is an solution that i found in my search resualt:

    http://forums.asp.net/t/1123520.aspx?Asynchronous+Post+Back+on+TextBox+TextChanged

    that work fine. but I whould like that  teach your solution.

    Thanks again my friend :)

    Sunday, August 21, 2016 12:35 PM
  • User954927490 posted

    but what is Url?

    URL is the url of that function which you are using to validate username in your ajax call.

    Tuesday, August 23, 2016 7:19 AM
  • User1122778340 posted

    Thank you

    Tuesday, August 23, 2016 7:23 AM