Textbox Select Text

Textbox Select Text

Post by Jim McGivn » Tue, 20 Dec 2005 01:55:11


On an aspx page I have an asp:TextBox.
I am able to give the textbox the focus when the page is loaded.
I would like to be able to select (highlight) the contents of the textbox
when it gets the focus, so that the user can type an entry to replace the
selected text, or tab-out of the textbox to keep the selected text.
I this behavior supported for an asp:TextBox ?
If so, how do I implement it ? Sample code would be appreciated.
How do I research this topic in Microsoft documentation ?
Thanks,
Jim
 
 
 

Textbox Select Text

Post by Teemu Keis » Tue, 20 Dec 2005 03:47:02

With custom attributes (expando attributes, typical to web controls) which
are passed as-is to the client-browser (and can be used to append js to the
HTML element)

Example:

<asp:TextBox ID="TextBox1" runat="server"onfocus="this.select()" />

which passes the onfocus="this.select()" to browser to the INPUT element
(which is rendered), and again causes client js functionality to select the
text in textbox when it receives the focus.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://www.yqcomputer.com/