ASP.NET Validation Group Workarounds



  • Hmmm, I just had a thought.

    You could probably do this on both the client and server side code...

    When going to validate, disable the validation controls for the input controls that do not need to be validated.
    Then set the validation group of all of the validation controls for the input controls that do need to be validated to X.

    Like this on the server side:

    if (rdoOne.Checked)
    {
       rfvOne.Enabled = true;
       rfvTwo.Enabled = true;
       rfvThree.Enabled = false;
       rfvOne.ValidationGroup = "X";
       rfvTwo.ValidationGroup = "X";
    
       Page.Validate("X");
       if(!Page.IsValid) { return; }
    }
    


  • If you're already going to the effort of disabling the validation controls that don't need to execute, then why bother changing the validation groups? Why not just do this:

    if (rdoOne.Checked)
    {
       rfvOne.Enabled = true;
       rfvTwo.Enabled = true;
       rfvThree.Enabled = false;
    
       Page.Validate();
       if(!Page.IsValid) { return; }
    }
    


  • Because I'm heavily CDO. But yeah, either way. How's that approach work out for you?



  • That should work. I could stick with the solution I currently have for client side which is allowing me to assign multiple validation groups to each control. Then on server side I could use this solution, just making sure to re-enable all of the validation controls once validation is complete.

    Off to try it out ...



  • I miss coding. 😢


Log in to reply