user1705172
user1705172

Reputation: 21

css styles are not applicable when textbox is disabled

When I set my textbox.Enabled = false, it loses all CSS Styles. I can set it to readonly, and all CSS Styles works well. But how can I keep css styles for disabled textbox?

Upvotes: 2

Views: 6989

Answers (3)

user1705172
user1705172

Reputation: 21

Thanks very much,

I found the solution to do it. There are no CSS style apply when I set Enabled=false.But when I set disabled=true,it works well.

Example:

[TextBox txtTest class="test" disabled="true"]

Upvotes: 0

Mr_Green
Mr_Green

Reputation: 41832

You can apply CSS styling on disabled inputs by using this:

input[disabled]
{
  /* Your CSS Styles */
  background-color:#F0F0F0 !important; 
  color:#303030 !important;
}

or

/* To make this work add class="disabled" in your HTML input tag (for IE6)*/
input[disabled='disabled'] 
{
  /* Your CSS Styles */
  background-color:#F0F0F0 !important; 
  color:#303030 !important;
}

and also You can apply CSS styling on read-only inputs by using this: (optional)

input[readonly]
{
  /* Your CSS Styles */
  background-color:#F0F0F0 !important; 
  color:#303030 !important;
}

Or else if you declared any Id or class to that input then replace input with that Id or class in the above code.

I am not sure about giving !important, once try without giving. If it works then Ok, otherwise consider !important in your CSS.

source: link

Upvotes: 3

Dinesh Guptha
Dinesh Guptha

Reputation: 97

There is a Slight difference between Read Only and Enabled. Read Only Can be Available only for the controls which will get the users INPUT. But Enabled is available to All the Controls Commonly to Restrict the Usage Of it.

**

- Enabled will affect the CSS not much But the Font Style(Color,Style), Control will not be available. 
- Read Only Does the Same Work Without Affecting Anything,Control Will be Available**

Upvotes: 0

Related Questions