tags:

views:

1236

answers:

1

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?

+2  A: 

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.

pbz
I'm not sure your CSS is right. Does setting el.disabled = true in javascript add an attribute to the tag for CSS to find? CSS3 includes a disabled pseudo-class - you could use both for extra insurance: "input[disabled], input:disabled { ... }"
Joel Mueller
what is the difference between using a Skin and a Css class in your second example.
Xaisoft
@XaisoftThe end result / html would be the same. The difference is that if you use a Skin you could use that in the future to change other properties on the TextBox. Also, if you change your mind about the CSS class name you only have to change the Skin in one place. With the CSS version you would have to update all the places you uses CssClass="disabled". This may or may not be an issue. With the CSS option you, obviously, can't change other TextBox properties.
pbz
@Joe MuellerI've also seen input[disabled='disabled'] but this doesn't seem to work with IE. "input[disabled]" seems to work with IE, FF, and Chrome (the three that I have tested). To be safe I guess it couldn't hurt to use input:disabled as well.
pbz