TextBox Web Server Control Overview
The TextBox Web server control provides a way for users to type information into an ASP.NET Web page, including text, numbers, and dates.
This topic contains:
Background
Code Examples
Class Reference
Background
The TextBox 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 set the TextMode property to TextBoxMode.MultiLine to display a multi-line text box (which renders as a textarea element). You can also change the TextMode property to TextBoxMode.Password to display a text box that masks user input. The text displayed in the TextBox control is available by using the Text property.
Security Note: |
---|
Setting the TextMode property to TextBoxMode.Password can help make sure that other people cannot see a password as it is being entered. However, the text entered into the text box is not encrypted in any way, and you should protect it as you would any other confidential data. For example, for increased security when posting a page with a password in it, you can use Secure Sockets Layer (SSL) and encryption. |
Security Note: |
---|
User input in an ASP.NET Web page can include potentially malicious client script. By default, the ASP.NET Web page validates that user input does not include script or HTML elements. For more information, see Script Exploits Overview. |
TextBox Events
The TextBox control raises a TextChanged event when the user leaves the control. By default, the event is not raised immediately; instead, it is raised on the server when the page is submitted. However, you can specify that the TextBox control should submit the page to the server as soon as the user leaves the field.
The TextBox Web server control does not raise an event each time the user enters a keystroke, only when the user leaves the control. You can have the TextBox control raise client-side events that you handle in client script, which can be useful for responding to individual keystrokes. For details, see Client Script in ASP.NET Web Pages.
TextBox Captions
You can use Label controls to create captions for TextBox controls. The caption can define an access key that users can press to navigate to the TextBox control. For details, see How to: Use Label Web Server Controls as Captions.
Auto-Completion in Text Boxes
Many browsers support an auto-completion feature that helps users fill information into text boxes based on values that the users have entered previously. The exact behavior of auto-completion depends on the browser. In general, browsers store values based on the text box's name attribute; any text box with the same name, even on a different page, will offer the same values to the user. Some browsers also support a vCard schema, which allows users to create a profile in the browser with predefined values for first name, last name, telephone number, e-mail address, and so on.
The TextBox control supports an AutoCompleteType property that provides you with these options for controlling how the browser works with auto-completion:
Disable auto-completion. If you do not want the browser to offer auto-completion for a text box, you can disable it.
Specify a vCard value to use as the auto-completion value for the field. The browser must support the vCard schema.
Code Examples
How to: Get and Set Values in TextBox Web Server Controls
How to: Respond to Changes in a TextBox Web Server Control
How to: Set a TextBox Web Server Control for Password Entry
How to: Specify Multiline Input for a TextBox Web Server Control
Back to top
Class Reference
The following table lists the classes that relate to the BulletedList control.
Member |
Description |
---|---|
The main class for the control. |
|
Specifies whether the TextBox control is in single-line, multi-line, or password mode. |
Back to top
See Also
Concepts
Overview of Web Application Security Threats