The Validation Application Block provides integration with Windows Forms applications and validates user input. The ValidationProvider
component part of the Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WinForms
assembly is an extender provider that adds additional properties to Windows Forms controls. Validation can be performed by using the Control.Validating
event or it can be invoked manually in our code using the ValidationProvider.PerformValidation(Control)
method. Additionally, it provides integration with Windows Forms ErrorProvider
component to display visual indication to the user of the error.
We must add reference to the Microsoft.Practices.EnterpriseLibrary.Validation.Integration.WinForms.dll
to leverage the integration features.
ValidationProvider
to the Toolbox. ValidationProvider
component to the Windows Forms. ValidationProvider
by selecting the ErrorProvider
component and by assigning the SourceTypeName
to the fully qualified name of the type to be validated. Optionally, RulesetName
can be configured to use a specific Rule Set; also the component can be enabled or disabled by setting the Enabled
property. Author
class, which consists of First Name, Last Name, and Email ID, since ValidationProvider
adds additional properties to the controls, we can configure SourcePropertyName
to the respective property name in the Author
class. ValidatedProperty
is set to Text
by default for a TextBox
control and PerformValidation
is set to True
by default. SourcePropertyName
determines the property to be used of the type configured in the ValidationProvider
. ValidateChildren
or the ValidationProvider.PerformValidation(Control)
method. ValidateChildren
method:this.ValidateChildren(ValidationConstraints.Visible);
ValidationProvider:
validationProviderAuthor.PerformValidation(textBoxFirstName);
3.145.9.148