Digital Colony!

Adding Javascript Select All to ASP.NET Control

A common user-interface technique to updating form fields is to have all the text selected when the user gives it focus. This allows the user the ability to clear out old text easily, without having to use the mouse and/or backspace button to clear out the selection themselves.
<asp:TextBox ID="txtSearch" runat="server" MaxLength="100" />
You can add the javascript code to select the text (this.select()) to the onclick or the onfocus event. Or you can add it to both.
txtSearch.Attributes.Add("onclick", "this.select();");
txtSearch.Attributes.Add("onfocus", "this.select();");

Labels: , ,

posted by MAS on Sep 15,2007

If you found this site helpful, consider buying me a cup of coffee. Smile

Digital Colony Copyright © 1999-2010 XHTML   508
Try...Catch Disclaimer: For brevity many examples do not include error handling. That is your responsibility.