(22 printed pages) Download the source code for this article.
Introduction and Confession The Dynamic Validation Configuration file Data Structures The Dynamic Validation Manager Class Using the Dynamic Validation Manager Conclusion Related Books I'd like to say that the ideas in this article were based on something noble, such as the hope of freeing the Web developer to focus on implementing business logic, or maybe a desire to create a framework that helps provide a more consistent user interface, but it just wasn't that way.
There are a set of properties common to every validator, irrespective of their type.
This means we don't have to specify, for example, "Fore Color='RED'" on every validation control we define.
If necessary, these default property values can be overridden for a given validator.
There will be two sections to the configuration file: one that defines the common and default property values used for all validators, and one that defines a collection of validators and properties to be applied to a given user input field.
The last thing we want to do is have to continually specify repeated properties for every validator control, so we use a Defaults section of the configuration file to specify them once.
Further, we needed a framework that helped create a consistent input validation that could be easily changed and modified without needing to change each and every ASPX page.
After a concentrated whiteboard session, we ended up with a version of the implementation presented below.
For the set of common validator properties, we will have a subsection of the configuration file that holds the common values to be applied to all dynamically created validators, irrespective of their type.
Each type of validator control also has a unique set of properties (for example, the Validation Summary's Show Message Box property), so we will need a subsection that holds the default property values.
In essence, each input field has an associated Place Holder control.
The Place Holder's ID property indexes into a configuration file to retrieve a collection of validators dynamically created and added to the Place Holder.
So, we all got to work, started developing our screens, and everything was going quite well. In one of the morning meetings, the User Interface team said they needed to change the language used to report validation errors.