1

I am having trouble with my code, I was able to implement it using code behind but it was not good as I have sliding panel (using jQuery) which were interfered with on post back.

The CheckBoxList is disabled by default with no auto postback.

I want the CheckBoxList to become enables if the CheckBox is checked.

Currently, I have this code:

$("#BizAppsCheckBox").click(function () {
        if (this.checked)
            $('#BizAppsCheckBoxList').removeAttr('disabled');
        else
            $('#BizAppsCheckBoxList').attr('disabled', 'disabled');
    });

How can I fix this issue?

Best working solution for me, thanks to the answers:

$(document).ready(function () {    
if ($("#BizAppsCheckBox").prop('checked') == false) {
                $('#BizAppsCheckBoxList *').prop('disabled', true);
            }
            else {
                $('#BizAppsCheckBoxList *').prop('disabled', false);
            }

$("#BizAppsCheckBox").click(function () {
                if (this.checked)
                    $('#BizAppsCheckBoxList *').prop('disabled', false);
                else
                    $('#BizAppsCheckBoxList *').prop('disabled', true) &
                $('#BizAppsCheckBoxList *').prop('checked', false);
            });
});
2
  • I tried all the solution but none are working for me.. Commented Aug 20, 2013 at 14:42
  • How are you disabling the CheckBoxList to begin with? Commented Aug 20, 2013 at 17:28

3 Answers 3

2

Try this :

You should use the ClientID cuz asp.net does provide different ID ( when under container)

$("#<%=BizAppsCheckBox.ClientID%> ").click(function () {
                if (this.checked)
                    $('#<%=BizAppsCheckBoxList.ClientID%>').prop('disabled',false);
                else
                    $('#<%=BizAppsCheckBoxList.ClientID%>').prop('disabled', true);
            });

edit

 $("#<%=BizAppsCheckBox.ClientID%>").click(function () {
                if (this.checked)
                    $('#<%=BizAppsCheckBoxList.ClientID%> *').prop('disabled', false);
                else
                    $('#<%=BizAppsCheckBoxList.ClientID%> *').prop('disabled', true);
            });
Sign up to request clarification or add additional context in comments.

2 Comments

please have a look above
thanks, your code works really good now but i still have one problem - when the page first loads the checkboxlist is enabled, if i do set it to "enabled=false". That messes up with the search results by not including the items clicked in the checkbox list. Can you help me with that please?
1

Use prop instead of attr, if ClientIDMode is not static then use ClientID of server controls

$("#<%= BizAppsCheckBox.ClientID %>").click(function () {
      if (this.checked)
           $('#<%= BizAppsCheckBoxList.ClientID %>').prop('disabled', true);
      else
           $('#<%= BizAppsCheckBoxList.ClientID %>').prop('disabled', false);
});

1 Comment

What is not working, can you please explain? do you get click event?
1

this will do the trick

$("#<%=BizAppsCheckBox.ClientID%>").click(function () {       
       $('#<%=BizAppsCheckBoxList.ClientID%>').prop('disabled',!this.checked);
});

or

$("#BizAppsCheckBox").click(function () {
         $('#BizAppsCheckBoxList').prop('disabled', !this.checked);
});

try using .on()

$("document").on("click","#<%=BizAppsCheckBox.ClientID%>",function(){
         $('#<%=BizAppsCheckBoxList.ClientID%>').prop('disabled',!this.checked);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.