Hey Folks:
I need to build a class or set of classes that will perform some server-side validation of a form in such a way that users of the form would simply have to add some user controls to the form, set some properties for the user controls, then call one ValidateForm method in a validation class to validate all of the user controls at once.
The idea I have so far is as follows:
1. For each type of control (checkbox, textbox, etc) I will have a user control, that will contain the control, any validation controls like required validators or regex validators, and also a label to output the result of any server side validation.
2. The user control will have properties that specify what type of server validation needs to be performed. For example, if the user control is for a textbox, there maybe a property called CheckAddress, so that it will check a database table for the existince of that the address in the database. This is just one example.
3. The User control will have a ServerValidate method, that will check it's corresdonding properties to determine what to validate, and then do so, returning an error or not depending on success or failure.
4. The page will then simply need to add the appropriate user controls, and set the correct properties depending on what should be validated.
My dilemna is the following - I need an easy way for the page to trigger the server validation of the controls on the page. What I would like is to be able to pass the user controls to my validation class on submission of the form, then have my class iterate through all of the user controls on the page and call each corresponding ServerValidate method. I am a little stumped on a good way of doing this - since I would like my validation class to handling the iteration but it does not have access to the user control objects, so what do I pass it and how does it determine which user control it is looking at so as to call the right method?
Thanks to anyone with any input on this - a little code snippet would be great if anyone has done this before
Thanks,
John Ginzo
GinzoTech Solutions
www.ginzotech.com