user5710892
user5710892

Reputation:

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

Upvotes: 0

Views: 771

Answers (2)

Suraj S
Suraj S

Reputation: 1019

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

Upvotes: 1

praty
praty

Reputation: 573

This should help after focus:

txtState.SelectionStart = txtState.Text.Length -1;
txtState.SelectionLength = 0;

Upvotes: 1

Related Questions