Search code examples
c#asp.netwebformscursortextchanged

How to set cursor after the text in a textbox on TextChange Event


I have a textbox txtZipCode. On the TextChange event, i am populating data in other two textboxes txtState and txtCity. What i want to do is, i want to set the cursor after the Text of txtState.

I am doing txtState.Focus() but, the cursor is displaying on the left side of the text...i want to set the cursor after the text.

Any Suggestions ?

Thanks in Advance


Solution

  • Try This, txtState.Attributes["onfocus"] = "javascript:this.setSelectionRange(this.value.length,this.value.length);";