Textbox Select Text

J

Jim McGivney

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
 
T

Teemu Keiski

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.
 

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

Members online

No members online now.

Forum statistics

Threads
474,433
Messages
2,571,683
Members
48,796
Latest member
Greg L.

Latest Threads

Top