ASP.NET PropertyProxyValidator implementation

Topics: Validation Application Block
Nov 1, 2010 at 5:06 PM


In our application we use some textboxes. These textboxes needs some validation logic. This logic is places in our business layer, and it uses already entlib validation blocks).
When we use default PropertyProxyValidator and the correct properties are set, validation rules are validated correctly (the validator shows an asteriks '*' and the errormessage
is shown in de validationsummery).

Now we have a simple problem. Our graphical disigner wants to change the backcolor (based on a css class), instead of showing some 'dirty' marks somewhere on our form.

Is there any example of code how to validate a value against some validation rules in some businessobject.

Something like:
ValidationResults results = ValidationFactory.Validatie("submittedValueInTextBox", "PropertyName", "BusinessObject");


Sander Bouwmeester


Nov 1, 2010 at 6:59 PM

If you need to validate a single property of an object, you can use the PropertyValidationFactory. Here is an example of its usage:

Type type = typeof(Customer);
PropertyInfo property = type.GetProperty("Name");

string ruleset = string.Empty;
var source = ValidationSpecificationSource.All;
var builder = new ReflectionMemberValueAccessBuilder();

Validator validator =
        type, property, ruleset, source, builder);

ValidationResults results = validator.Validate(customer);