I have a group of text boxes that have required field validation hooked up to them. Obviously they all share the same validation group name. I have a check box for terms of service that needs to be checked before clicking on the submit button actually does anything.
Is there some C# code that will say if this box isn’t checked, fail the validation group?
Or is there a better way?
edit:
I added a custom validator and used this in my code behind. Does not work.
protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = false;
if (cbxTerms.Checked)
args.IsValid = true;
}
I figured out how to do it. I made a textbox, assigned a req field validator to it. Put the textbox 99999px off the screen. In my c# i said if the check box is checked, the textbox.text = “”; in the checkbox check changed event I said if the check box is checked then the textbox.text = “1”;. Much easier than any other solution I could find
Edit: Better to use a hidden field.