ASP.NET Syntax ASP.NET Syntax for Web Controls
The TextBox control generates single-line and multiline text boxes.
Declarative Syntax
<asp:TextBox
AccessKey = "string"
AutoCompleteType = "None | Disabled | Cellular | Company |
Department | DisplayName | Email | FirstName | Gender |
HomeCity | HomeCountryRegion | HomeFax | HomePhone | HomeState |
HomeStreetAddress | HomeZipCode | Homepage | JobTitle | LastName |
MiddleName | Notes | Office | Pager | BusinessCity |
BusinessCountryRegion | BusinessFax | BusinessPhone | BusinessState |
BusinessStreetAddress | BusinessUrl | BusinessZipCode | Search"
AutoPostBack = "True | False"
BackColor = "color name | #dddddd"
BorderColor = "color name | #dddddd"
BorderStyle = "NotSet | None | Dotted | Dashed | Solid | Double | Groove |
Ridge | Inset | Outset"
BorderWidth = size
CausesValidation = "True | False"
Columns = integer
CssClass = "string"
Enabled = "True | False"
EnableTheming = "True | False"
EnableViewState = "True | False"
Font-Bold = "True | False"
Font-Italic = "True | False"
Font-Names = "string"
Font-Overline = "True | False"
Font-Size = "string | Smaller | Larger | XX-Small | X-Small | Small |
Medium | Large | X-Large | XX-Large"
Font-Strikeout = "True | False"
Font-Underline = "True | False"
ForeColor = "color name | #dddddd"
Height = size
ID = "string"
MaxLength = integer
OnDataBinding = "DataBinding event handler"
OnDisposed = "Disposed event handler"
OnInit = "Init event handler"
OnLoad = "Load event handler"
OnPreRender = "PreRender event handler"
OnTextChanged = "TextChanged event handler"
OnUnload = "Unload event handler"
ReadOnly = "True | False"
Rows = integer
runat = "server"
SkinID = "string"
Style = "string"
TabIndex = integer
Text = "string"
TextMode = "SingleLine | MultiLine | Password"
ToolTip = "string"
ValidationGroup = "string"
Visible = "True | False"
Width = size
Wrap = "True | False"
/>
For information on the individual members of this class, see TextBox in the class library.
Property |
Description |
AutoPostBack |
true if client-side changes in the control automatically cause a postback to the server; false otherwise. The default is false. |
Columns |
The width of the control in characters. This property differs from the Width, which sets the absolute width of the control independent of the character spacing. |
MaxLength |
The maximum number of characters allowed within text box. This property has no effect unless the TextMode property is set to SingleLine or Password. |
Rows |
Number of rows within the text box. This property has no effect unless the TextMode property is set to MultiLine. |
Text |
The text that the user has entered into the box. |
TextMode |
Indicates whether the text box is in single-line, multi-line, or password mode. Possible values are Single, MultiLine, and Password. |
Wrap |
Indicates whether text should wrap around as users type text into a multiline control. This property has no effect unless the TextMode property is set to MultiLine. |
Base properties |
The properties inherited from the base WebControl class. |
Event ( and parameters ) |
Description |
onTextChanged ( Object sender, EventArgs e ) |
Raised on the server when the contents of the text box change. This event does not cause the Web Forms page to be posted to the server unless the AutoPostBack property is set to true.
The event argument object e has no properties. |
The TextBox control is an input control that lets the user enter text. By default, the TextMode property is set to SingleLine, which creates a text box with only one line. You can also set the property to MultiLine or Password. MultiLine creates a text box with more than one line. Password creates a single-line text box that masks the value entered by the user.
The display width of the text box is determined by its Columns property. If the text box is a multiline text box, the display height is determined by the Rows property.
The following shows a sample declaration for a TextBox control in an .aspx file. The control is multiline with columns set to 30 characters and rows set to 5 lines. The method txtChangedHandler is designated to receive control when the onTextChanged event occurs. In this example, the page is immediately sent to the server once the event fires because autopostback is set to true.
<asp:textbox runat=server
id="myTextBox"
textmode = "MultiLine"
backcolor = "ivory"
columns=30 rows=5
text = "The multiline textbox ... "
onTextChanged = "txtChangedHandler"
autopostback />
Show me
TextBox Class TextBox Web Server Control