c# - ASP checkbox 'checked' attribute always returning true -
i have several asp:checkboxes
on webform filled in on page load, returned on button submit.
the buttons returning same server boolean behind them, no matter whether changed on client side before being returned. after checking clientid of variables, same not down hidden ids or that.
aspx
<script type="text/javascript"> function slidetable(link) { $(link).parent().next().toggle() $(link).find(".navplus").toggleclass("rotate1"); $(link).find(".navplus").toggleclass("rotate"); var txt = $(link).parent().next().is(':visible') ? 'minimise' : 'view all'; $(link).find(".navplus").text(txt); }; function boxchange(box) { //change has happened @ point if ($(box).prop("checked")==true) { $(box).attr("checked", "checked"); } else { $(box).removeattr("checked"); } var table = $(box).closest('table'); var allchecked = $('#subjectstable :checkbox:checked').length == $('#subjectstable :checkbox').length; if (allchecked) { $(table).prev().find(":input").prop("checked", true); $(table).prev().find(":input").attr("checked", true); } else { $(table).prev().find(":input").prop("checked", false); $(table).prev().find(":input").attr("checked", false); } }; </script> <div> <span class="headerspan" onclick="slidetable(this)" style="clear:both" > <img class="logo-image" alt="halsburylogo" src="../images/sitestyle/logo.png"/> <span class="navplus rotate1">view all</span> </span> <input onclick="chkheader_click(this)" style="float:none; display:inline" type="checkbox" id="chksubjects"/> </div> <table id="subjectstable" class="subscriptiontable"> <tr> <td style="width: 300px"> <label>art</label></td> <td> <asp:checkbox onclick="boxchange(this)" id="chkart" cssclass="chksubject" runat="server" /></td> </tr> </table>
when submit button clicked, value of chkart same. - upon checking, clientid of chkart on serverside chkart
edit: in page load event following code present:
chkart.checked = //a bool database
chkart.checked = //a bool database
this code in page_load
? unless you're conditionally running code (which aren't in question @ least...) being executed every time page loads. page_load
invoked whenever request made page, postback or otherwise.
so page receiving changed values, ignoring them , resetting them previous state.
you can conditionally check postbacks in page_load
:
if (!ispostback) chkart.checked = //a bool database
that way initial state of checkbox
set on initial load of page, , not re-set on every postback.
Comments
Post a Comment