Hi Peter,
I also found out that one can selectively enable and disable client side
validation merely by setting the enable flag of the validation control to
true or false. I was able to take advantage of that in my code to simplify
validation for all my validation controls by creating the two following
methods:
// Returns true if validation succeeds for the given validation control, or,
// if the control is not enabled (in which case no validation should occur)
private bool IsValidControl(BaseValidator control)
{
if (!control.Enabled)
{
return true;
}
control.Validate();
return (control.IsValid);
}
private bool IsValidForm()
{
bool valid = true;
valid &= IsValidControl(ReqValUserID);
valid &= IsValidControl(RegexUserID);
valid &= IsValidControl(ReqValFirstName);
valid &= IsValidControl(RegexFirstName);
valid &= IsValidControl(RegexMiddleInitial);
valid &= IsValidControl(ReqValLastName);
valid &= IsValidControl(RegexLastName);
valid &= IsValidControl(ReqValEmail);
valid &= IsValidControl(RegexEmail);
valid &= IsValidControl(ReqValPhone);
valid &= IsValidControl(RegexPhone);
valid &= IsValidControl(ReqValNotes);
valid &= IsValidControl(ReqValReject);
return valid;
}
Finally, I invoked the IsValidForm() method in my submit button onclick
handler as follows:
if (!IsValidForm())
{
return;
}
Tim