views:

1756

answers:

3

I've got a radiobuttonlist with a bunch of list items, some of them disabled. The label control beside the radio button turns gray, which can be hard to read. How do I change the color of the label? I've tried CSS, changing the forecolor - nothing seems to work:

currentButton.Attributes.Add("class", "disabled");

Any ideas?

A: 

You can use the CSS attribute selector for this:

input.myclass[disabled=disabled] { color: #FF0000; }

Update: Fixed the answer since I misunderstood the question.

Cide
That's not what I'm trying to do.Once it's disabled, I would like to change the forecolor color of the text beside the radio button.
Dave
My mistake. I corrected the answer.
Cide
I've added your code, set the radiobuttonlist's CssClass="myclass" and it doesn't work.Am I implementing your correctly?
Dave
+1  A: 

Although I've never used asp.net built-in controls, I'm guessing here that your RadioButtonList is trying to be smart enough and renders some CSS (inline or class/id) to visually reflect its control state.

You should take a look at the generated HTML and spot such CSS code then try to override it. If they designed that control the way I think, maybe there's a property that lets you change that particular state color. But if there isn't such a property, you always have the option to override that with your custom CSS.

If the CSS is rendered inline (blame MS for that LOL) post back here and I'll try to get back with a workaround.

It's a sharepoint publishing page - that's a whole other can of worms.
Dave
what's the rendered html for those radio buttons?
<tr> <td><span disabled="disabled" class="disabled"><input id="ctl00_PlaceHolderMain_Wizard1_radTimeList_0" type="radio" name="ctl00$PlaceHolderMain$Wizard1$radTimeList" value="2" disabled="disabled" /><label for="ctl00_PlaceHolderMain_Wizard1_radTimeList_0">9:00 AM - 9:15 AM Not Available</label></span></td> </tr>I've tried overriding the class disabled, but it's still not black.
Dave
Dave, it looks to me that the radio button gets disabled by your code, so I'd look into your CSS and try setting span.disabled label{color:#000}
I'm disabling them myself in the code-behind when the page loads, I just want the disabled text to be another color other than gray.I just tried your suggestion and it didn't work. I'm really stumped here :P
Dave
dave you should use some dom tool and look for style rules that prevent your own to override them.
A: 
    $(document).ready(function() {
        setRadioButtonListStyle();
    });

    function setRadioButtonListStyle() {
        var radioButtonListServerId = "rblOption";
        var labels = $("label[for*='" + radioButtonListServerId + "']");
        $.each(labels, function() {
            this.parentElement.disabled = false;
            }
        });

        var tables = $("table[id*='" + radioButtonListServerId + "']");
        $.each(tables, function() {
            this.disabled = false;
        });
    }
Yang Ching