Language

TextBox.Text Property

Definition

Gets or sets the text content of the TextBox control.

public:
 virtual property System::String ^ Text { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Bindable(true)]
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.EncodedInnerDefaultProperty)]
public virtual string Text { get; set; }
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.EncodedInnerDefaultProperty)]
[System.ComponentModel.Bindable(true, System.ComponentModel.BindingDirection.TwoWay)]
public virtual string Text { get; set; }
[]
[]
member this.Text : string with get, set
[]
[]
member this.Text : string with get, set
Public Overridable Property Text As String

Property Value

The text displayed in the TextBox control. The default is an empty string ("").

Implements

Attributes

Examples

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.

<%@ Page Language="C#" AutoEventWireup="True" %>





    TextBox Example
    


  

TextBox Example

+ =

<%@ Page Language="vb" AutoEventWireup="false" %>





    TextBox Example
    


  

TextBox Example

+ =

Remarks

Use the Text property to specify or determine the text displayed in the TextBox control. To limit the number of characters accepted by the control, set the MaxLength property. If you want to prevent the text from being modified, set the ReadOnly 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 LocalizableAttribute 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 "Test", the browser will display "Test", not "Test" in bold.

Applies to

See also