asp.net c#.net jquery / javascript how to enable or disable a requiredfieldvalidator using a checkbox -
i having issue trying enable or disable requiredfieldvalidator using checkbox. obviously, when checkbox checked want enabled , unchecked disabled. when checkbox checked opens fileupload want register if there not file chosen. here of code.
html:
<tr> <td> <asp:checkbox id="chkexeclaf" text="executed laf" runat="server" oncheckedchanged="chkexeclaf_checkedchanged" /> </td> <td id="tblexeclaf"> <asp:fileupload id="fileupload1" runat="server" cssclass="fileupload1" /> <asp:requiredfieldvalidator id="rfvexeclaf" controltovalidate="fileupload1" errormessage="*required" forecolor="red" runat="server" /> </td> <td> <asp:checkbox id="chkdatedleaseabstract" text="dated lease abstract" runat="server" /> </td> <td> <asp:fileupload id="fileupload2" runat="server" cssclass="fileupload2" /> </td> </tr>
code behind:
protected void chkexeclaf_checkedchanged(object sender, eventargs e) { if (fileupload1.hasfile) { rfvexeclaf.enabled = false; } else { rfvexeclaf.enabled = true; } }
jquery:
<script type="text/javascript"> $(function () { $('.fileupload1').attr('disabled', true); $('.rfvexeclaf').attr('disabled', true); $('.rfvexeclaf').hide(); $('.fileupload1').hide(); $('#<%=chkexeclaf.clientid %>').click(function () { if ($(this).is(':checked')) { $('.fileupload1').removeattr('disabled'); $('.rfvexeclaf').removeattr('disabled'); $('.rfvexeclaf').show(); $('.fileupload1').show(); } else { $('.fileupload1').attr('disabled', true); $('.rfvexeclaf').attr('disabled', true); $('.rfvexeclaf').hide(); $('.fileupload1').hide(); } }); }); </script>
have tried adding breakpoint codebehind , see if breakpoint hit on checkedchanged?
if doesn't hit may want add autopostback = 'true'
chkexeclaf
Comments
Post a Comment