12 December, 2011

ASP.NET Textbox Selectall() property



12-Dec-2011


I am currently writing a form where I needed to highlight and select all text in a textbox when it is selected (onfocus), cause that is what user will be doing: copy and paste, so that in effect requires selecting the whole text string currently in the textbox, to replace it with new value.


I got two answers from my search routing, server side, and client side, and that is coming from a single article.


Here’s how:


In Page_Load event, add below code:


myTextBox.Attributes.Add("onfocus", "this.select()")


The other way is what I tested, and it worked, so I assume above works as well:





Hoe this helps you, as it did me.


Till then. Ciao!


Reference: selectall() property in C# for textbox control



Enhanced by Zemanta

No comments:

Post a Comment