Skip to main content
Version: 4.1

Validation

Namespace: Wisej.Web

Assembly: Wisej.Framework (4.1.0.0)

Adds a common validation system to any Control.

public class Validation : Component, IExtenderProvider, IUserData

You can drop this extender on any design surface to add validation rules to any control at design time using the added ValidationRules property. You can also use this component at runtime and invoke the SetValidationRules method directly.

Validation rules are executed in the order they are added to the array. When a validation rule fails validation, the next rules are NOT executed and the Cancel property of the control's Validating event is set to true.

Constructors

Instance member Validation()

Initializes a new instance of the Validation class.

Instance member Validation(containerControl)

Initializes a new instance of the Validation class attached to a ContainerControl.

NameTypeDescription
containerControlContainerControlThe ContainerControl to monitor for errors.

Instance member Validation(container)

Initializes a new instance of the Validation class attached to a IContainer implementation.

NameTypeDescription
containerIContainerAn IContainer that represents the container of the Validation extender.

Properties

Instance member ContainerControl

ContainerControl: Returns or sets the container ContainerControlthat provides the BindingContext for binding to the IDataErrorInfo interface implemented by a DataSource. (Default: null)

Instance member DataMember

String: Returns or sets the list within a data source to monitor for errors. (Default: "")

Instance member DataSource

Object: Returns or sets the data source that the Validation extender monitors for errors. (Default: null)

Instance member ErrorProvider

IErrorProvider: Associates an IErrorProvider to the Validation extender."/> (Default: null)

When this property is null (default), the validation extender sets the InvalidMessage property of the control being validated to the corresponding InvalidMessage when a validation rule fails. Otherwise it invokes the SetError method passing the control that failed validation and the corresponding InvalidMessage string.

You may use an instance of ErrorProvider to display error icons and messages. But you can also implement the IErrorProvider interface in a custom class and manage errors however required by the application.

A third option is to assign a Label (or any Control that implements IErrorProvider) to the ErrorProvider property to let the validation extender set the text property to the corresponding InvalidMessage string.

info

The Label (or any Control that implements IErrorProvider) is automatically hidden (Visible is set to false) when there is no error message to display.

Instance member Tag

Object: Returns or sets the object that contains programmer-supplied data associated with the Validation extender. (Default: null)

Methods

Instance member BindToDataAndErrors(dataSource, dataMember)

Sets the DataSource and DataMember properties.

ParameterTypeDescription
dataSourceObjectA data set based on the IList interface to be monitored for errors.
dataMemberStringA collection within the dataSource to monitor for errors.

Instance member CanExtend(extendee)

Returns a value indicating whether a control can be extended.

ParameterTypeDescription
extendeeObjectThe control to be extended.

Returns: Boolean. true if the control can be extended; otherwise, false.

Instance member Clear()

Removes all validation rules.

Instance member GetValidationRules(control)

Returns the collection of ValidationRule associated with the specified control .

ParameterTypeDescription
controlControlControl associated with the validation rules to retrieve.

Returns: ValidationRule[]. Array of the validation rules associated to the control .

Instance member OnValidated(e)

Fires the Validated event.

ParameterTypeDescription
eValidationEventArgs

Instance member OnValidating(e)

Fires the Validating event.

ParameterTypeDescription
eValidationEventArgs

Instance member ResetValidationRules(control)

Removes all the validation rules from the control .

ParameterTypeDescription
controlControlControl to remove from the Validation extender.

Instance member SetValidationRules(control, rules)

Sets the list of validation rules associated with the specified control .

ParameterTypeDescription
controlControlControl associated with the validation rules.
rulesValidationRule[]List of validation rules to enforce on the specified control .

Instance member UpdateBinding()

Updated the bindings.

Events

Instance member Validated

ValidationEventHandler Fired after any control associated to the Validation extender has been successfully validated.

You can add an handler to this event and handle the successful validation of all the controls that have a set of validation rules in one place.

Instance member Validating

ValidationEventHandler Fired when the any control associated to the Validation extender is being validated.

You can add an handler to this event and handle the validation of all the controls that have a set of validation rules in one place.

Implements

NameDescription
IUserDataProvides access to the UserData and Tag properties associated to the component implementing this interface.