TextBox::ReadOnly Property
Gets or sets a value indicating whether the contents of the TextBox control can be changed.
Assembly: System.Web (in System.Web.dll)
[ThemeableAttribute(false)] [BindableAttribute(true)] public: virtual property bool ReadOnly { bool get (); void set (bool value); }
<asp:TextBox ReadOnly="True|False" />
Property Value
Type: System::Booleantrue 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.
Important |
|---|
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.
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. |
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Important