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: , ,

 

Digital Colony Copyright © 1999-2008 XHTML   508
This site uses Blogger, which is not 100% XHTML compliant.
Try...Catch Disclaimer: For brevity many examples do not include error handling. That is your responsibility.