Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

selectall() property in C# for textbox control

Tags:

c#

asp.net

I know, there is a property for textbox control in windows form, called selectall().

I am trying to achieve the same in my web app, for a textbox, once it recieves the focus(), i am trying to select all the text in the textbox.

I know I can write some jquery for this, but, is there any other easier way to achieve this?

like image 974
Ron Avatar asked Apr 01 '11 17:04

Ron


3 Answers

Try this:

<asp:TextBox ID="Textbox1" runat="server" onFocus="this.select()" />
like image 59
BrandonZeider Avatar answered Nov 05 '22 16:11

BrandonZeider


No, you cannot do this without some client side scripting code. The code is very simple, though. In your Page_Load event, just specify:

myTextBox.Attributes.Add("onfocus", "this.select()")
like image 26
Heinzi Avatar answered Nov 05 '22 16:11

Heinzi


Textbox1.Attributes["onFocus"] = "this.select()";
like image 45
Noel Vaca Moreno Avatar answered Nov 05 '22 15:11

Noel Vaca Moreno