views:

87

answers:

1

Greeting;

I have asp.net dropdownlist control with Ajax CascadingDropDown control.

I also I have asp.net checkbox control. I want to enable/disable CascadingDropDown when the checkbox checked/unchecked using jquery.

I tried diffrent ways but they did not work and if I want to set enable property for the dropdownlist to false it will not work so I have to set the CascadingDropDown enable property to false to disable it but I do not know how.

this is one of the code I tried:

<asp:CheckBox ID="chkWF" runat="server"  onclick="enableDDL"/>

<asp:DropDownList ID="WF" runat="server"></asp:DropDownList>

<cc1:CascadingDropDown ID="WF_CascadingDropDown" runat="server" 
                    TargetControlID="WF" 
                    Category="WF"  
                    LoadingText="Please Wait ..." 
                    PromptText="Select Work Field ..." 
                    ServiceMethod="GetWorkField" 
                    ServicePath="../ServiceTags.asmx" Enabled="True">
                </cc1:CascadingDropDown>






function enableDDL() {

             $('#<%= chkOccup.ClientID %>').click(function() {
                 if ($('#<%= WF_CascadingDropDown.ClientID %>').attr('disabled') != true)
                     $('#<%= WF_CascadingDropDown.ClientID %>').attr('disabled', true);
                 else
                     $('#<%= WF_CascadingDropDown.ClientID %>').attr('disabled', false);

                     });

         }
A: 

Instead of defining a bool value for the disabled attribute just use the string "disabled" and to enable it, just remove the attribute.

function enableDDL() {
    $('#<%= chkOccup.ClientID %>').click(function() {
        if ($('#<%= WF_CascadingDropDown.ClientID %>').attr('disabled'))
            $('#<%= WF_CascadingDropDown.ClientID %>').attr('disabled', 'disabled');
        else
            $('#<%= WF_CascadingDropDown.ClientID %>').removeAttr('disabled');
     });
}

If that doesn't work, are you sure the result of $('#<%= WF_CascadingDropDown.ClientID %>') is a select element?

Peter

related questions