Freigeben über


TextBox Web Server Control Declarative Syntax

Creates single-line and multiline text boxes.

<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"
/>

Remarks

The TextBox server 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.

Use the Text property to determine the contents of the TextBox control. You can limit the number of characters that can be entered in the control by setting the MaxLength property. Set the Wrap property to true to specify that the contents of the cell should automatically continue on the next line when the end of the text box is reached.

For more information about the TextBox Web server control's properties and events, see the TextBox class documentation.

Example

The following example shows a sample declaration for a TextBox control in an .aspx file. The control is a multiline text box that displays a maximum of ten lines. The text is formatted in Arial font if the browser supports fonts for controls.

Security noteSecurity Note

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.

<asp:TextBox id="txtLogin" runat="server"
     Text="" Font-Names="Arial" 
     Font-Size="10"
     BackColor="lightblue"
     TextMode="MultiLine"
     Height="43px"
/>
<asp:TextBox id="txtLogin" runat="server"
     Text="" Font-Names="Arial" 
     Font-Size="10"
     BackColor="lightblue"
     TextMode="MultiLine"
     Height="43px"
 />

See Also

Reference

TextBox

Other Resources

Web Server Control Syntax