Displays a text box control for user input.
Assembly: System.Web (in System.Web.dll)
[ValidationPropertyAttribute(L"Text")] [ControlValuePropertyAttribute(L"Text")] [AspNetHostingPermissionAttribute(SecurityAction::LinkDemand, Level = AspNetHostingPermissionLevel::Minimal)] [AspNetHostingPermissionAttribute(SecurityAction::InheritanceDemand, Level = AspNetHostingPermissionLevel::Minimal)] public ref class TextBox : public WebControl, IPostBackDataHandler, IEditableTextControl, ITextControl
The server control is an input control that lets the user enter text. By default, the TextMode property of the control is set to TextBoxMode.SingleLine, which displays a single-line text box. However, you can also use the control to display a multiline text box or a text box that masks user input by changing the value of the TextMode property to TextBoxMode.MultiLine or TextBoxMode.Password, respectively. The text displayed in the control is specified or determined by using the Text property.
The 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 Columns property. If the control is a multiline text box, the number of rows it displays is determined by the Rows property. To display text that wraps within the control, set the Wrap property to true.
You can also specify how data is entered in the control by setting a few properties. To prevent the text displayed in the control from being modified, set the ReadOnly property to true. If you want to limit the user input to a specified number of characters, set the MaxLength property.
For a list of initial property values for an instance of , see the TextBox 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 Controls, How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings, and Validating User Input in ASP.NET Web Pages.
The markup rendered by default for this control might not conform to accessibility standards such as the Web Content Accessibility Guidelines 1.0 (WCAG) priority 1 guidelines. For details about accessibility support for this control, see ASP.NET Controls and Accessibility.
The following code example demonstrates how to use the control to get user input. When the user clicks the Add button, the sum of the values entered in the text boxes is displayed.
This example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.