Require checkbox via customvalidator


/ Published in: C#
Save to your folder(s)

RequiredFieldValidator doesn't support checkboxes, but a customvalidator does the trick.


Copy this code and paste it in your HTML
  1. public void ValidateChecked(object sender, ServerValidateEventArgs e)
  2. {
  3. e.IsValid = chkMyChkBox.Checked;
  4. }
  5.  
  6. //Client side method, referenced in customvalidtor ClientValidationFunction attribute:
  7. <script type="text/javascript" language="javascript">
  8. function ValidateCheckboxIsChecked(sender, args)
  9. {
  10. args.IsValid = (document.getElementById("CheckBox1").checked);
  11. }
  12. </script>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.