0

I have several checkboxes inside an UpdatePanel of asp.net

Let's say, I have 3 checkboxes in that panel. Each time, one checkbox is checked, the previous checked checkbox will be unchecked.

I have tried like this:

<asp:CheckBox ID="CheckBoxExport1" CssClass="checkboxSingle" />                                     

<asp:CheckBox ID="CheckBoxExport1" CssClass="checkboxSingle" />                                     

<asp:CheckBox ID="CheckBoxExport1" CssClass="checkboxSingle" /> 

In js:

 $('.checkboxSingle').live('click', function (e) {

        if ($(this).is(':checked')) {
            $(".checkboxSingle").attr('checked', false);
            $(this).attr('checked', 'checked')
        }
    });

The click is function but the rest does not.

4
  • Your code works fine for me here jsfiddle.net/wYH44/2. Commented Oct 1, 2011 at 11:34
  • 1
    Why don't you just use <asp:RadioButton>? Also, in ASP, shouldn't the value of the checked-attribute be true instead of checked? Commented Oct 1, 2011 at 11:38
  • is it a problem if I put them inside an UpdatePanel? @ipr101 Commented Oct 1, 2011 at 12:08
  • @devn The update panel could be making a difference - see forums.asp.net/t/1189519.aspx/1 Commented Oct 1, 2011 at 12:48

3 Answers 3

3

What's happening is that on postback the page reloads and the JavaScript doesn't re-run. I'm posting from my phone so I don't have the code on me. But google "updatepanel JavaScript postback". You need to use an asp page event.

I'll edit this later if you tell me you can't find it.

Good luck

Sign up to request clarification or add additional context in comments.

Comments

0

It is simple, (asp:CheckBox) is rendered as a (span) with label and input field with type="check". So when you are trying to say $(".chkboxClass").removeAttr('checked'); you are actually calling the (span) tag and that is the reason it is not working. To make it works just add:

$(".chkboxClass :input").removeAttr('checked');

Good luck

Comments

0

this is similar to DigitalFox response, but this is how I got it to work:

$(".checkboxSingle input").is(":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.