Tutorial :Can an ASP.NET Validation Rule belong to multiple groups?



Question:

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!


Solution:1

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


Solution:2

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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »