C# – Can you change the back color of an asp.net textbox when it is disabled

asp.netc++

When I set Enabled to false, it sets the background of the textbox to a grey color, can this be changed? Right now, the grey background with black text makes it a little hard to read.

Or maybe, I have to use the readonly property instead and set the backcolor myself, is this correct?

Best Solution

There are several ways to achieve this:

1) Use CSS to change the look for all the input controls. Just put "input[disabled] { border:solid 1px red; }" in your CSS file.

2) Using ASP.NET skins, in the Skin file you could write:

<asp:TextBox runat="server" SkinID="disabled" CssClass="disabled"></asp:TextBox>

This would set the disabled CSS class only for that TextBox

3) Manually assigning a CSS class to only the TextBoxes you want disabled, like:

<asp:TextBox runat="server" ID="x" Enabled="false" CssClass="disabled"></asp:TextBox>

4) Create your custom control that inherits from TextBox and configure it that way.

Related Question