TextBox::ReadOnly Property


Gets or sets a value indicating whether the contents of the TextBox control can be changed.

Namespace:   System.Web.UI.WebControls
Assembly:  System.Web (in System.Web.dll)

property bool ReadOnly {
	virtual bool get();
	virtual void set(bool value);

Property Value

Type: System::Boolean

true if the contents of the TextBox control cannot be changed; otherwise, false. The default value is false.

Use the ReadOnly property to specify whether the contents of the TextBox 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 TextBox control cannot change this property; only the developer can.


The Text value of a TextBox control with the ReadOnly 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 Text value that is read-only. The value of the Text 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 ThemeableAttribute and ASP.NET Themes and Skins.

The following code example demonstrates how to use the ReadOnly property to prevent any changes to the text displayed in the TextBox control.

System_CAPS_security Security 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.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 1.1
Return to top