views:

54

answers:

2

Is it possible for an ASP.NET Validation Rule to belong to multiple groups? I'd like to validate the same control in different ways based on what mode the form is in using a single Validator.

For the purposes of this question, the modes are Simple, which requires fewer fields, or Complex, which requires more fields. I know I can write CustomValidators (which I have done in the past), but I'd like a simpler solution.

So, I'd like to combine the following:

<asp:RequiredFieldValidator ValidationGroup="Simple" ControlToValidate="Name" />
<asp:RequiredFieldValidator ValidationGroup="Complex" ControlToValidate="Name" />

Thanks!

+1  A: 

There is no support for multiple validation groups on a validator or button in the ASP.NET Validators

garpunkal
+3  A: 

No, unfortunately they cannot. But to my understanding your page is never shown in simple and complex mode at the same time, so maybe you should just add the validator from codebehind and set the validationgroup based on the current mode.

klausbyskov