I am looking for the best way to set the validation group for all of the controls contained in a user control. Most of the controls in the control are created dynamically when the control is loaded. It has quite a few input fields and validators.
I would like to save time by setting the validation for all the controls and validators with some sort of function that could just loop through everything and set it.
It seems though that there is no consistent interface that includes validation group for all of the different controls that have the property.
Should I use reflection to check for Validation group, I know I can do this, but is there a better way?
We are using C# by the way.
Any help would be appreciated. Thanks!
EDIT: I put the answer down below for anyone who wants the code.
Just wanted to mark this answered.
Here is the code I used to set the validation group. I decided to go with using reflection, since I could check types for those I know have ValidationGroup, and cast and set, but there are a lot of types to check, and it could miss new controls that may be added in the future. Would have been sweet if the ValidationGroup were part of some kind of interface that things had to implement.