Examples

A Visual Studio Web site project with source code is available to accompany this topic: Download.

The following code example demonstrates how to use the TextBox control to get user input. When the user clicks the Add button, the sum of the values entered in the text boxes is displayed.

Important

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.

Remarks

Introduction

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 also use the TextBox 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 TextBox control is specified or determined by using the Text property.

The 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 Columns property. If the TextBox 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 TextBox control, set the Wrap property to true.

You can also specify how data is entered in the TextBox 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 TextBox, see the TextBox constructor.

Copies the properties not encapsulated by the Style object from the specified Web server control to the Web server control that this method is called from. This method is used primarily by control developers.

Searches the current naming container for a server control with the specified id and an integer, specified in the pathOffset parameter, which aids in the search. You should not override this version of the FindControl method.