System.Web
1.0.5000.0
2.0.0.0
Gtk# is thread aware, but not thread safe; See the <link location="node:gtk-sharp/programming/threads">Gtk# Thread Programming</link> for details.
System.Web.UI.WebControls.WebControl
System.Web.UI.IEditableTextControl
System.Web.UI.IPostBackDataHandler
System.Web.UI.SupportsEventValidation
System.Web.UI.ControlValueProperty("Text", null)
System.Web.UI.ParseChildren(true, "Text")
System.ComponentModel.Designer("System.Web.UI.Design.WebControls.PreviewControlDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.ComponentModel.Design.IDesigner")
System.Web.UI.ControlBuilder(typeof(System.Web.UI.WebControls.TextBoxControlBuilder))
System.Web.UI.ValidationProperty("Text")
System.ComponentModel.DefaultProperty("Text")
System.ComponentModel.DefaultEvent("TextChanged")
System.Web.UI.DataBindingHandler("System.Web.UI.Design.TextDataBindingHandler, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
In this topic:
-
Introduction
-
Declarative Syntax
Introduction
The server control is an input control that lets the user enter text. By default, the property of the control is set to TextBoxMode.SingleLine, which displays a single-line text box. However, you can also use the control to display a multiline text box or a text box that masks user input by changing the value of the property to TextBoxMode.MultiLine or TextBoxMode.Password, respectively. The text displayed in the control is specified or determined by using the property.
The 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 property. If the control is a multiline text box, the number of rows it displays is determined by the property. To display text that wraps within the control, set the property to true.
You can also specify how data is entered in the control by setting a few properties. To prevent the text displayed in the control from being modified, set the property to true. If you want to limit the user input to a specified number of characters, set the property.
For a list of initial property values for an instance of , see the constructor.
This control can be used to accept user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. You can use validation controls to verify user input before displaying the input text in a control. ASP.NET provides an input request validation feature to block script and HTML in user input. For more information, see Securing Standard Controls, How to: Protect Against Script Exploits in a Web Application by Applying HTML Encoding to Strings, and Introduction to Validating User Input in ASP.NET Web Pages.
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"
/>
Displays a text box control for user input.
Constructor
Use this constructor to create and initialize a new instance of the class.
The following table shows the initial property value for an instance of .
-
Property
Initial value
-
TagKey
HtmlTextWriterTag.Input
Initializes a new instance of the class.
1.0.5000.0
2.0.0.0
Method
System.Void
a
This method is used primarily by control developers to insert the additional attributes and styles to the output stream for a control. This method overrides .
Adds HTML attributes and styles that need to be rendered to the specified instance.
1.0.5000.0
2.0.0.0
Method
System.Void
To be added
Overridden to allow only literal controls to be added as the property.
An that represents the parsed element.
1.0.5000.0
2.0.0.0
Property
2.0.0.0
System.Web.UI.Themeable(false)
System.ComponentModel.DefaultValue(System.Web.UI.WebControls.AutoCompleteType.None)
System.Web.UI.WebControls.AutoCompleteType
To be added.
To assist with data entry, Microsoft Internet Explorer 5 and later and some other browsers support a feature referred to as AutoComplete. AutoComplete monitors a text box and creates a list of values entered by the user. When the user returns to the text box at a later time, the list is displayed. Instead of retyping a previously entered value, the user can simply select the value from this list. Use the property to control the behavior of the AutoComplete feature for a control. The enumeration is used to represent the values that you can apply to the property.
Not all browsers support the AutoComplete feature. Check with your browser to determine compatibility.
By default, the property for a control is set to AutoCompleteType.None. With this setting, the control shares the list with other controls with the same property across different pages. You can also share a list between controls based on a category, instead of an property. When you set the property to one of the category values (such as AutoCompleteType.FirstName, AutoCompleteType.LastName, and so on), all controls with the same category share the same list. You can disable the AutoComplete feature for a control by setting the property to AutoCompleteType.Disabled.
Refer to your browser documentation for details on configuring and enabling the AutoComplete feature. For example, to enable the AutoComplete feature in Internet Explorer version 5 or later, select Internet Options from the Tools menu, and then select the Content tab. Click the AutoComplete button to view and modify the various browser options for the AutoComplete feature.
For more information about the AutoComplete feature in Internet Explorer, see Using AutoComplete in HTML Forms in the MSDN Library.
This property cannot be set by themes or style sheet themes. For more information, see and ASP.NET Themes Overview.
Gets or sets a value that indicates the AutoComplete behavior of the control
Property
System.Boolean
To be added: an object of type 'bool'
Use the property to specify whether an automatic postback to the server will occur when the control loses focus. Pressing the ENTER or the TAB key while in the control is the most common way to change focus.
If the control's parent container contains a button marked as the default button (for example, if the container's or property is set), the default button's Click event is not raised in response to the automatic postback.
This property cannot be set by themes or style sheet themes. For more information, see and ASP.NET Themes Overview.
Gets or sets a value that indicates whether an automatic postback to the server occurs when the control loses focus.
1.0.5000.0
2.0.0.0
System.Web.UI.Themeable(false)
System.ComponentModel.DefaultValue(false)
Property
2.0.0.0
System.Web.UI.Themeable(false)
System.ComponentModel.DefaultValue(false)
System.Boolean
To be added.
Use the property to determine whether validation is performed on both the client and the server when a control is set to validate when a postback occurs. Page validation determines whether the input controls associated with a validation control on the page all pass the validation rules specified by the validation control.
By default, a control does not cause page validation when the control loses focus. To set the control to validate when a postback occurs, set the property to true and the property to true.
When the value of the property is set to true, you can also use the property to specify the name of the validation group for which the control causes validation.
This property cannot be set by themes or style sheet themes. For more information, see and ASP.NET Themes Overview.
Gets or sets a value indicating whether validation is performed when the control is set to validate when a postback occurs.
Property
System.Int32
To be added: an object of type 'int'
To be added
Gets or sets the display width of the text box in characters.
1.0.5000.0
2.0.0.0
System.ComponentModel.DefaultValue(0)
Method
2.0.0.0
System.Boolean
The method checks whether the postback data of the control is different from its previous value and, if so, loads the content and returns true.
Processes the postback data for the control.
true if the posted content is different from the last posting; otherwise, false.
The index within the posted collection that references the content to load.
The collection posted to the server.
Property
System.Int32
To be added: an object of type 'int'
Use the property to limit the number of characters that can be entered in the control.
This property is applicable only when the property is set to TextBoxMode.SingleLine or TextBoxMode.Password.
This property cannot be set by themes or style sheet themes. For more information, see and ASP.NET Themes Overview.
Gets or sets the maximum number of characters allowed in the text box.
1.0.5000.0
2.0.0.0
System.Web.UI.Themeable(false)
System.ComponentModel.DefaultValue(0)
Method
System.Void
To be added
Registers client script for generating postback events prior to rendering on the client, if is true.
An that contains the event data.
1.0.5000.0
2.0.0.0
Method
System.Void
The event is raised when the content of the text box changes between posts to the server.
A control must persist some values between posts to the server for this event to work correctly. Be sure that view state is enabled for this control.
Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.
The method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
Raises the event. This allows you to handle the event directly.
A that contains event information.
1.0.5000.0
2.0.0.0
Method
2.0.0.0
System.Void
The method invokes the method if the posted data for the control has changed. If the property is true, the controls in the validation group set in the property are validated.
Invokes the method when the posted data for the control has changed.
Property
System.Boolean
To be added: an object of type 'bool'
Use the property to specify whether the contents of the control can be changed. Setting this property to true will prevent users from entering a value or changing the existing value. Note that the user of the control cannot change this property; only the developer can.
The value of a control with the property set to true is sent to the server when a postback occurs, but the server does no processing for a read-only text box. This prevents a malicious user from changing a value that is read-only. The value of the property is preserved in the view state between postbacks unless modified by server-side code.
This property cannot be set by themes or style sheet themes. For more information, see and ASP.NET Themes Overview.
Gets or sets a value indicating whether the contents of the control can be changed.
1.0.5000.0
2.0.0.0
System.Web.UI.Themeable(false)
System.ComponentModel.DefaultValue(false)
System.ComponentModel.Bindable(true)
Method
System.Void
a
The method renders the begin tag and end tag of the control to the object for output on the client. If the property is set to , the content of the control is rendered as an HTML <textarea> element.
The method is used primarily by control developers extending the functionality of the control.
Renders the control to the specified object.
1.0.5000.0
2.0.0.0
Property
System.Int32
To be added: an object of type 'int'
Use the property to specify the number of rows displayed in a multiline text box.
This property is applicable only when the property is set to TextBoxMode.MultiLine.
This property cannot be set by themes or style sheet themes. For more information, see and ASP.NET Themes Overview.
Gets or sets the number of rows displayed in a multiline text box.
1.0.5000.0
2.0.0.0
System.Web.UI.Themeable(false)
System.ComponentModel.DefaultValue(0)
Method
2.0.0.0
System.Object
This method is used primarily by control developers.
View state is the accumulation of the values of a server control's properties. These values are automatically placed in the server control's property, which is an instance of the class. This property's value is then persisted to a string object after the save state stage of the server control's life cycle. For more information, see ASP.NET Application Life Cycle Overview.
When view state is saved, this string object is returned to the client as a variable that is stored in a hidden HTML input element. When you author custom server controls, you can improve efficiency by overriding this method and modifying your server control's ViewState property. For more information, see ASP.NET State Management Overview.
Saves the changes to the text box view state since the time the page was posted back to the server.
The that contains the changes to the view state. If no view state is associated with the object, this method returns null.
Method
1.0.5000.0
2.0.0.0
System.Boolean
This member is an explicit interface member implementation. It can be used only when the instance is cast to an interface.
Loads the posted text box content if it is different from the last posting.
true if the posted content is different from the last posting; otherwise, false.
The index within the posted collection that references the content to load.
The collection posted to the server.
Method
1.0.5000.0
2.0.0.0
System.Void
This member is an explicit interface member implementation. It can be used only when the instance is cast to an interface.
Invokes the method whenever posted data for the text box has changed.
Property
System.Web.UI.HtmlTextWriterTag
a
To be added
Gets the HTML tag for the text box control. This property is protected.
1.0.5000.0
2.0.0.0
Property
System.String
To be added: an object of type 'string'
Use the property to specify or determine the text displayed in the control. To limit the number of characters accepted by the control, set the property. If you want to prevent the text from being modified, set the property.
The value of this property, when set, can be saved automatically to a resource file by using a designer tool. For more information, see and ASP.NET Globalization and Localization.
When the text box is rendered, the contents of this property are HTML-encoded. For example, if you set this property to "<b>Test</b>", the browser will display "<b>Test</b>", not "Test" in bold.
Gets or sets the text content of the control.
1.0.5000.0
2.0.0.0
System.ComponentModel.Editor("System.ComponentModel.Design.MultilineStringEditor,System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", "System.Drawing.Design.UITypeEditor, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
System.ComponentModel.Localizable(true)
System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.EncodedInnerDefaultProperty)
System.ComponentModel.DefaultValue("")
System.ComponentModel.Bindable(true, System.ComponentModel.BindingDirection.TwoWay)
Event
System.EventHandler
The event is raised when the content of the text box changes between posts to the server. The event is only raised if the text is changed by the user; the event is not raised if the text is changed programmatically.
A control must persist some values between posts to the server for this event to work correctly. Be sure that view state is enabled for this control.
For more information about handling events, see Consuming Events.
Occurs when the content of the text box changes between posts to the server.
1.0.5000.0
2.0.0.0
Property
System.Web.UI.WebControls.TextBoxMode
To be added: an object of type 'TextBoxMode'
Use the property to specify whether a control is displayed as a single-line, multiline, or password text box.
When the control is in multiline mode, you can control the number of rows displayed by setting the property. You can also specify whether the text should wrap by setting the property.
If the control is in password mode, all characters entered in the control are masked.
This property cannot be set by themes or style sheet themes. For more information, see and ASP.NET Themes Overview.
Gets or sets the behavior mode (single-line, multiline, or password) of the control.
1.0.5000.0
2.0.0.0
System.Web.UI.Themeable(false)
System.ComponentModel.DefaultValue(System.Web.UI.WebControls.TextBoxMode.SingleLine)
Property
2.0.0.0
System.ComponentModel.DefaultValue("")
System.Web.UI.Themeable(false)
System.String
To be added.
Validation groups allow you to assign validation controls on a page to a specific category. Each validation group can be validated independently from other validation groups on the page. Use the property to specify the name of the validation group for which the control causes validation when it posts back to the server.
This property has an effect only when the property is set to true. When you specify a value for the property, only the validation controls that are part of the specified group are validated when the control posts back to the server. If you do not specify a value for this property and the property is set to true, all validation controls on the page that are not assigned to a validation group are validated when the control posts back to the server.
This property cannot be set by themes or style sheet themes. For more information, see and ASP.NET Themes Overview.
Gets or sets the group of controls for which the control causes validation when it posts back to the server.
Property
System.Boolean
To be added: an object of type 'bool'
Use the property to specify whether the text displayed in a multiline control automatically continues on the next line when the text reaches the end of the control.
This property is applicable only when the property is set to TextBoxMode.MultiLine.
Gets or sets a value indicating whether the text content wraps within a multiline text box.
1.0.5000.0
2.0.0.0
System.ComponentModel.DefaultValue(true)