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 asp.net 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.
ValidationResults results = ValidationFactory.Validatie("submittedValueInTextBox", "PropertyName", "BusinessObject");
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);