Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Select Default Text?

I am using asp.net 2.0 and would like to know if there is a way to have the default text in a textbox automatically selected.

I would like to programatically recreate the effect that you get if you would click in a text box and hit ctrl+a.

I can set the focus to the text box without a problem. I would now just like to select the default text.

If you have any ideas let me know.
[407 byte] By [dagdamor67] at [2007-11-11 8:17:29]
# 1 Re: Select Default Text?
http://www.felgall.com/jstip41.htm
Phil Weber at 2007-11-11 23:13:16 >
# 2 Re: Select Default Text?
Is there a similar function for <asp:TextBox> instead of the html element?
dagdamor67 at 2007-11-11 23:14:16 >
# 3 Re: Select Default Text?
An asp:textbox is simply an HTML input element. If you're asking, 'Is it possible to highlight all text in a textbox from server-side code,' the answer is no.
Phil Weber at 2007-11-11 23:15:25 >
# 4 Re: Select Default Text?
So to have it work I would need to go to javascript or vbscript.
dagdamor67 at 2007-11-11 23:16:25 >
# 5 Re: Select Default Text?
Correct. And if you use VBScript, it will only work in Internet Explorer, so I strongly recommend that you use Javascript.
Phil Weber at 2007-11-11 23:17:24 >