Stopping the Submit

  • 4 October 2004
  • 1 reply
  • 15 views

Badge +1
Hello,

I have a list of checkboxes that are data bound to a dataset on a page.

When the user click a K2Button i want to make sure that at least one of the check boxes is selected. If it isn't i want to stop the form being posted.

I've looked into asp.net validation controls but have had trouble using them in the past. Is there a way to stop the page submitting if "checkbox.selected.count = 0" :?:

thanks

1 reply

Badge +8
You could use a client-side javascript function (for example, FormValidation) on the form's onsubmit event. The function can test your checkboxes and return false if none of them are checked, or return true if any of them are checked.

In your <Form> tag, add onsubmit="return FormValidation()". If your function returns false, the form will not be submitted, if it returns true, the form will be submitted.

Reply