Am using the following code to check/uncheck all checkboxes in a list. The code works fine and the text is updated, however, the checkbox that is causing the toggle does not stay checked. It is always unchecked. If I add an alert to the first function in the toggle, I can see that the box is checked. After selecting OK, the box is unchecked. Any idea why this is happening or what I can do to get the cbCheckall.Checked property to toggle properly as well?
<script type="text/javascript">
$(document).ready(function () {
$("#" + document.getElementById('<%= Me.cb1.ClientID %>').attributes.getNamedItem("ID").nodeValue).toggle(
function () {
$("input[id*=" + document.getElementById('<%= Me.userControl.FindControl("cbl1").ClientID %>').attributes.getNamedItem('ID').nodeValue + "]").attr('checked', 'checked');
$("#" + document.getElementById('<%= Me.cb1.ClientID %>').attributes.getNamedItem("ID").nodeValue).next("label").text("(Unselect All)");
},
function () {
$("input[id*=" + document.getElementById('<%= Me.userControl.FindControl("cbl1").ClientID %>').attributes.getNamedItem('ID').nodeValue + "]").removeAttr('checked');
$("#" + document.getElementById('<%= Me.cb1.ClientID %>').attributes.getNamedItem("ID").nodeValue).next("label").text("(Select All)");
});
});
</script>
All help is greatly appreciated!