Associate PropertyProxyValidator to SelfValidation result

Topics: Validation Application Block
Mar 11, 2009 at 11:05 PM
This may be trivial but is there a way to associate a SelfValidation method (or more precisely a ValidationResult that's created in the method) to a property on the business object so that a web form can use a PropertyProxyValidator to display text next to a UI widget when the underlying object property is invalid?
Mar 12, 2009 at 2:43 AM
SelfValidation won't be trigerred when using PropertyProxyValidator.  Can you elaborate a bit about the scenario you are facing?  Maybe we can come up with other solution.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
Mar 12, 2009 at 4:27 PM
Edited Mar 12, 2009 at 4:32 PM
Sure.  I have an class that must comply with some fairly complex validation requirements.  I decorate several of the properties of the class with the standard validator attributes (NotNullValidator, PropertyComparisonValidator, etc).  The more complex validation rules are coded within methods decorated with the SelfValidation attribute.

My UI is an ASP web form.  I have several PropertyProxyValidator controls that are tied to the properties of my class decorated with the validator attributes.  When validation fails (I validate on Save) I list all the validation results in a list and the PropertyProxyValidator controls display an asterisk next to the UI controls that need to be corrected.  What I would like to do is to display an asterisk next to the UI controls based on results of SelfValidation methods.

For example, I have properties on my class that are validated using different logic based on current user, the state of other properties (even properties of child objects) and other external factors.  In these cases I would still like to display an asterisk next to the UI control that needs to change to satisfy the validation requirements.  I thought there might be a way to use the PropertyProxyValidators to do this.

Another way I can think of is to set a key or tag on the ValidationResult and then have the UI examine these keys to manually draw the asterisks accordingly but this seems dirty to me.

I wanted to stay away from custom validators because of maintainability issues.  The validation rules may potentially change often and it's much easier for someone who's not familiar with the application code or application block to add a new method to the class (or edit an existing method) with the SelfValidation attribute than it is to create a new custom validator. 
Mar 13, 2009 at 2:17 AM

I believe custom validators are the only way to accomplish this (aside from dirty solutions of course).  There's no support in  EntLib for associating validation methods/results to PropertyProxyValidator.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.