# Validation

Namespace: **Wisej.Web**

Assembly: **Wisej.Framework** (4.0.0.0)

Adds a common validation system to any [Control](/api/wisej.web/general/control.md).

{% tabs %}
{% tab title="C#" %}

```csharp
public class Validation : Component, IExtenderProvider, IUserData
```

{% endtab %}

{% tab title="VB.NET" %}

```visual-basic
Public Class Validation
    Inherits Component
    Implements IExtenderProvider, IUserData
```

{% endtab %}
{% endtabs %}

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](#setvalidationrules-control-rules) 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](https://docs.microsoft.com/dotnet/api/system.componentmodel.canceleventargs.cancel) property of the control's [Validating](/api/wisej.web/general/control.md#validating) event is set to true.

## Constructors

### ![](/files/hsR4ok3152WyAf8J2C1u) Validation()

Initializes a new instance of the [Validation](/api/wisej.web/extenders/validation.md) class.

### ![](/files/hsR4ok3152WyAf8J2C1u) Validation(containerControl)

Initializes a new instance of the [Validation](/api/wisej.web/extenders/validation.md) class attached to a [ContainerControl](/api/wisej.web/containers/containercontrol.md).

| Name                 | Type                                                              | Description                                                                                  |
| -------------------- | ----------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| **containerControl** | [ContainerControl](/api/wisej.web/containers/containercontrol.md) | The [ContainerControl](/api/wisej.web/containers/containercontrol.md) to monitor for errors. |

### ![](/files/hsR4ok3152WyAf8J2C1u) Validation(container)

Initializes a new instance of the [Validation](/api/wisej.web/extenders/validation.md) class attached to a [IContainer](https://docs.microsoft.com/dotnet/api/system.componentmodel.icontainer) implementation.

| Name          | Type                                                                                 | Description                                                                                                                                                                                 |
| ------------- | ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **container** | [IContainer](https://docs.microsoft.com/dotnet/api/system.componentmodel.icontainer) | An [IContainer](https://docs.microsoft.com/dotnet/api/system.componentmodel.icontainer) that represents the container of the [Validation](/api/wisej.web/extenders/validation.md) extender. |

## Properties

### ![](/files/hsR4ok3152WyAf8J2C1u) ContainerControl

[ContainerControl](/api/wisej.web/containers/containercontrol.md): Returns or sets the container [ContainerControl](/api/wisej.web/containers/containercontrol.md)that provides the [BindingContext](/api/wisej.web/data-binding/wisej.web.bindingcontext.md) for binding to the [IDataErrorInfo](https://docs.microsoft.com/dotnet/api/system.componentmodel.idataerrorinfo) interface implemented by a [DataSource](#datasource). (Default: `null`)

### ![](/files/hsR4ok3152WyAf8J2C1u) DataMember

[String](https://docs.microsoft.com/dotnet/api/system.string): Returns or sets the list within a data source to monitor for errors. (Default: `""`)

### ![](/files/hsR4ok3152WyAf8J2C1u) DataSource

[Object](https://docs.microsoft.com/dotnet/api/system.object): Returns or sets the data source that the [Validation](/api/wisej.web/extenders/validation.md) extender monitors for errors. (Default: `null`)

### ![](/files/hsR4ok3152WyAf8J2C1u) ErrorProvider

[IErrorProvider](/api/wisej.web/interfaces/wisej.web.ierrorprovider.md): Associates an [IErrorProvider](/api/wisej.web/interfaces/wisej.web.ierrorprovider.md) to the [Validation](/api/wisej.web/extenders/validation.md) extender."/> (Default: `null`)

When this property is null (default), the validation extender sets the [InvalidMessage](/api/wisej.web/interfaces/wisej.web.ivalidation.md#invalidmessage) property of the control being validated to the corresponding [InvalidMessage](/api/wisej.web/extenders/validation/wisej.web.validationrule.md#invalidmessage) when a validation rule fails. Otherwise it invokes the [SetError](/api/wisej.web/interfaces/wisej.web.ierrorprovider.md#seterror-control-value) method passing the control that failed validation and the corresponding [InvalidMessage](/api/wisej.web/extenders/validation/wisej.web.validationrule.md#invalidmessage) string. You may use an instance of [ErrorProvider](#errorprovider) to display error icons and messages. But you can also implement the [IErrorProvider](/api/wisej.web/interfaces/wisej.web.ierrorprovider.md) interface in a custom class and manage errors however required by the application. A third option is to assign a [Label](/api/wisej.web/content/wisej.web.label.md) (or any [Control](/api/wisej.web/general/control.md) that implements [IErrorProvider](/api/wisej.web/interfaces/wisej.web.ierrorprovider.md)) to the [ErrorProvider](/api/wisej.web/extenders/validation/wisej.web.validationrule.md#errorprovider) property to let the validation extender set the text property to the corresponding [InvalidMessage](/api/wisej.web/extenders/validation/wisej.web.validationrule.md#invalidmessage) string.

{% hint style="info" %}
The [Label](/api/wisej.web/content/wisej.web.label.md) (or any [Control](/api/wisej.web/general/control.md) that implements [IErrorProvider](/api/wisej.web/interfaces/wisej.web.ierrorprovider.md)) is automatically hidden ([Visible](/api/wisej.web/general/control.md#visible) is set to false) when there is no error message to display.
{% endhint %}

### ![](/files/hsR4ok3152WyAf8J2C1u) Tag

[Object](https://docs.microsoft.com/dotnet/api/system.object): Returns or sets the object that contains programmer-supplied data associated with the [Validation](/api/wisej.web/extenders/validation.md) extender. (Default: `null`)

## Methods

### ![](/files/hsR4ok3152WyAf8J2C1u) BindToDataAndErrors(dataSource, dataMember)

Sets the [DataSource](#datasource) and [DataMember](#datamember) properties.

| Parameter      | Type                                                          | Description                                                                                                                           |
| -------------- | ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
| **dataSource** | [Object](https://docs.microsoft.com/dotnet/api/system.object) | A data set based on the [IList](https://docs.microsoft.com/dotnet/api/system.collections.ilist) interface to be monitored for errors. |
| **dataMember** | [String](https://docs.microsoft.com/dotnet/api/system.string) | A collection within the *dataSource* to monitor for errors.                                                                           |

### ![](/files/hsR4ok3152WyAf8J2C1u) CanExtend(extendee)

Returns a value indicating whether a control can be extended.

| Parameter    | Type                                                          | Description                 |
| ------------ | ------------------------------------------------------------- | --------------------------- |
| **extendee** | [Object](https://docs.microsoft.com/dotnet/api/system.object) | The control to be extended. |

**Returns:** [Boolean](https://docs.microsoft.com/dotnet/api/system.boolean). true if the control can be extended; otherwise, false.

### ![](/files/hsR4ok3152WyAf8J2C1u) Clear()

Removes all validation rules.

### ![](/files/hsR4ok3152WyAf8J2C1u) GetValidationRules(control)

Returns the collection of [ValidationRule](/api/wisej.web/extenders/validation/wisej.web.validationrule.md) associated with the specified *control* .

| Parameter   | Type                                         | Description                                               |
| ----------- | -------------------------------------------- | --------------------------------------------------------- |
| **control** | [Control](/api/wisej.web/general/control.md) | Control associated with the validation rules to retrieve. |

**Returns:** [ValidationRule\[\]](/api/wisej.web/extenders/validation/wisej.web.validationrule.md). Array of the validation rules associated to the *control* .

### ![](/files/hsR4ok3152WyAf8J2C1u) OnValidated(e)

Fires the [Validated](#validated) event.

| Parameter | Type                                                                                        | Description |
| --------- | ------------------------------------------------------------------------------------------- | ----------- |
| **e**     | [ValidationEventArgs](/api/wisej.web/extenders/validation/wisej.web.validationeventargs.md) |             |

### ![](/files/hsR4ok3152WyAf8J2C1u) OnValidating(e)

Fires the [Validating](#validating) event.

| Parameter | Type                                                                                        | Description |
| --------- | ------------------------------------------------------------------------------------------- | ----------- |
| **e**     | [ValidationEventArgs](/api/wisej.web/extenders/validation/wisej.web.validationeventargs.md) |             |

### ![](/files/hsR4ok3152WyAf8J2C1u) ResetValidationRules(control)

Removes all the validation rules from the *control* .

| Parameter   | Type                                         | Description                                                                               |
| ----------- | -------------------------------------------- | ----------------------------------------------------------------------------------------- |
| **control** | [Control](/api/wisej.web/general/control.md) | Control to remove from the [Validation](/api/wisej.web/extenders/validation.md) extender. |

### ![](/files/hsR4ok3152WyAf8J2C1u) SetValidationRules(control, rules)

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

| Parameter   | Type                                                                                  | Description                                                      |
| ----------- | ------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| **control** | [Control](/api/wisej.web/general/control.md)                                          | Control associated with the validation rules.                    |
| **rules**   | [ValidationRule\[\]](/api/wisej.web/extenders/validation/wisej.web.validationrule.md) | List of validation rules to enforce on the specified *control* . |

### ![](/files/hsR4ok3152WyAf8J2C1u) UpdateBinding()

Updated the bindings.

## Events

### ![](/files/hsR4ok3152WyAf8J2C1u) Validated

[ValidationEventHandler](/api/wisej.web/extenders/validation/wisej.web.validationeventhandler.md) Fired after any control associated to the [Validation](/api/wisej.web/extenders/validation.md) 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.

### ![](/files/hsR4ok3152WyAf8J2C1u) Validating

[ValidationEventHandler](/api/wisej.web/extenders/validation/wisej.web.validationeventhandler.md) Fired when the any control associated to the [Validation](/api/wisej.web/extenders/validation.md) 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

| Name                                                          | Description                                                                                                     |
| ------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| [IUserData](/api/wisej.web/interfaces/wisej.web.iuserdata.md) | Provides access to the `UserData` and `Tag` properties associated to the component implementing this interface. |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wisej.com/api/wisej.web/extenders/validation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
