Partager via


Introduction to the TextBox Control 

Applications use the TextBox control to enable users to enter a string. The TextBox control can mask input for passwords if the user's device supports it. A TextBox control must be placed within a Form or Panel control, or inside a control's template on a ASP.NET mobile Web page. You can also drag it onto a mobile user control.

Security noteSecurity Note

A TextBox accepts user input, which is a potential security threat. By default, ASP.NET mobile Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.

Blank Text Box

Applications set an initial value for the TextBox control with the Text property. The Size property specifies the expected width of the input string in characters. The TextBox control scales its input box according to the value of the Size property. A value of 0 indicates that the TextBox control uses its initial size settings. The input string (and the initial string) can contain more characters than specified in Size. If the user enters a string that is too long for the input box, previous input characters scroll. You can set a maximum length for the input string using the MaxLength property.

To accept only numeric input, set the Numeric property to true. However, not all markup languages support this setting. For example, HTML does not.

Set the alignment of the control with the Alignment property. The alignment can be set to Left, Center, or Right. If no value is specified for the alignment, the TextBox control uses the default alignment. Customize the text appearance with the ForeColor, Font, and StyleReference properties. To insert a line break after the TextBox control, set the BreakAfter property to true.

To use a TextBox control to retrieve a password from the user, set the Password property to true. If supported by the browser, the TextBox control masks or hides the input on the target device.

NoteNote

Using a password text box does not encrypt the input data or protect it during transport from the browser to the server. Pages containing a password text box should be accessed only with a secure SSL connection to protect the data.

You can use data binding to connect properties of a TextBox control to a data source. Doing so enables the property values to be determined at run time.

By applyingdevice filters, applications can customize the TextBox control for particular devices. The device filters enable applications to selectively override the values of several of the TextBox control's properties, depending on the type of mobile device on which the control is displayed.

See Also

Tasks

How to: Add and Configure a TextBox Control

Reference

TextBox

Concepts

Overriding Properties
Introduction to the Form Control
Introduction to the Panel Control

Other Resources

Using Device Filters