System.Web.UI.WebControls.TextBox Class

Displays a text box control for user input.

See Also: TextBox Members


[System.Web.UI.ControlValueProperty("Text", null)]
[System.Web.UI.ParseChildren(true, "Text")]
[System.ComponentModel.Designer("System.Web.UI.Design.WebControls.PreviewControlDesigner, System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")]
[System.Web.UI.DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, System.Design, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public class TextBox : WebControl, System.Web.UI.IEditableTextControl, System.Web.UI.IPostBackDataHandler


In this topic:


The System.Web.UI.WebControls.TextBox server control is an input control that lets the user enter text. By default, the TextBox.TextMode property of the control is set to TextBoxMode.SingleLine, which displays a single-line text box. However, you can also use the System.Web.UI.WebControls.TextBox control to display a multiline text box or a text box that masks user input by changing the value of the TextBox.TextMode property to TextBoxMode.MultiLine or TextBoxMode.Password, respectively. The text displayed in the System.Web.UI.WebControls.TextBox control is specified or determined by using the TextBox.Text property.

The System.Web.UI.WebControls.TextBox control contains several properties that allow you to control the appearance of the control. The display width of the text box, in characters, is determined by its TextBox.Columns property. If the System.Web.UI.WebControls.TextBox control is a multiline text box, the number of rows it displays is determined by the TextBox.Rows property. To display text that wraps within the System.Web.UI.WebControls.TextBox control, set the TextBox.Wrap property to true.

You can also specify how data is entered in the System.Web.UI.WebControls.TextBox control by setting a few properties. To prevent the text displayed in the control from being modified, set the TextBox.ReadOnly property to true. If you want to limit the user input to a specified number of characters, set the TextBox.MaxLength property.

For a list of initial property values for an instance of System.Web.UI.WebControls.TextBox, see the TextBox.#ctor constructor.


This control can be used to accept user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. You can use validation controls to verify user input before displaying the input text in a control. ASP.NET provides an input request validation feature to block script and HTML in user input. For more information, see Securing Standard ControlsHow to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings, and Introduction to Validating User Input in ASP.NET Web Pages.

Declarative Syntax




Namespace: System.Web.UI.WebControls
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 1.0.5000.0,