Most developers craft hard-coded program logic to verify that a phone number consists of 7 or 10 digits; that an IP address consists of 4 octets; that a country name matches 1 of 193 choices, etc. NET 2.0 provides some support for streamlining input validation, it barely scratches the surface of automating and simplifying the input validation process.
If you ever search MSDN for the topic, you'll find most of the articles discuss hard-coded validationbut maintaining hand-written, custom code for each element that requires validation is a maintenance nightmare.
Handle) ' Locks the form if "Me" is the form Lock Window Update(0&) ' Unlocks whatever was locked previously It doesn't stop the user from entering text but the added (or changed or removed) text won't appear until after the unlock. Have you set the Causes Validation property of the Save button to true?
If yes, when the focus is moved from one of these textboxes to the Save button, the textbox's Validating event will be raised.
A modular, data-driven validation engine approach provides a more natural interface, more flexibility, and is easier to maintain.
Visual Studio lets you specify property values at design time for a variety of components; using that approach for defining validation attributes is a natural extension, and makes incorporating robust validation simpler for developers.
I just discovered that the Masked Text Box control allows you to set the type of data which should be entered in the control and helps you do the validation of that data when necessary.In this case, you needn't cycle through every control and call its Select method to force validation. NET Application Architect, Enthusiast, & Evangelist T. Bradley - news: OH**************@TK2MSFTNGP04gbl... |I have a windows form that I want to force validation on controls (text | boxes) when the user clicks a "Save" button.However, if the user doesn't edit in any textbox on the form and click the Save button directly, the textbox's Validating event won't be raised. The only way I've found to do | this is to cycle through every control and call it's . This | is clunky though because you can see a flash in each text box as it's being | validated. Select() | End if | Next c | End Sub | | Each control has code in their Control_Validating event that fires off an | errorprovider.The flexibility of storing validation settings in a configuration file makes validation easy to change, allowing developers and administrators to modifiy or customize validation properties without recompiling and redeployingand without needing the source code.You'll find that using the validation engine discussed here, you can instrument a wide range of validation criteria with very few lines of code.