How to select the text in a TextBox

A

ad

I have a Textbox (Text) in a web form.
I use
this.SetFocus(Text1);

to set the focus on Text1.
How can I let the text in Text1 selected when the Text1 get focus?
 
A

ad

I use:

myTextBox.Attributes["onfocus"] = myTextBox.ClientID + ".sclect();";

But it can't work.
 
E

Eliyahu Goldin

You can do it on client side with a javascript call myTextBox.select();

Eliyahu
 
E

Eliyahu Goldin

When do you want the textbox to get focus and become selected? When the page
loads? When a button is clicked?

Eliyahu
 
E

Eliyahu Goldin

ok, you can take this way. Just try

myTextBox.Attributes["onfocus"] = "this.select();";

Eliyahu


ad said:
I use:

myTextBox.Attributes["onfocus"] = myTextBox.ClientID +
".sclect();";

But it can't work.



ad said:
Thanks,
But I can't do.
Please give me some code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top