asp.net.ph

Skip Navigation Links

Introduction to the TextBox Control

Controls You Can Use on Web Forms   ASP.NET Standard Controls   TextBox Control


The TextBox Web server control provides a way for users to type information into a Web Forms page, including text, numbers, and dates. The TextBox control can be configured in several ways, as described in the following:

Configuration Description
Single-line Users type information in a single line. You can optionally limit the number of characters that the control accepts.
Password Like a single-line TextBox control, but the characters users type are masked with asterisks ( * ) to hide them.
Multi-line Users type information in a box that displays multiple lines and allows text wrapping.

NOTE: User input in a Web Forms page can include potentially malicious client script. By default, the Web Forms page validates that user input does not include script or HTML elements.

TextBox Events

The TextBox control raises a TextChanged event when the user leaves the control. This event, though, is not raised immediately by default; instead, it is raised on the server when the Web Form is submitted. To submit the page as soon as the user leaves the control, the AutoPostBack property must be set.

NOTE: The TextBox 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 Programming Web Forms with Client Script.

TextBox Accessibility

The TextBox class inherits an AccessKey property from the base WebControl class, which can be used to define an access key that users can press to navigate to the TextBox control.

Alternatively, a TextBox control can use a Label control for its caption, which too can be set to use an access key. For details, see Using Label Controls as Captions.

Auto-Completion in TextBox Controls

Most browsers support an auto-completion feature that helps users fill information into text boxes based on values 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 HTML 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.

See Also

Setting a TextBox Control for Password Entry   Specifying Multiline Input for a TextBox Control



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note