VAB: Accessing Tags when using PropertyProxyValidator

Topics: Validation Application Block
Jun 29, 2007 at 4:05 PM
Edited Jun 29, 2007 at 4:07 PM
I am experimenting with Validation Application Block to determine how to best use it in an ASP.NET application.

One of my requirements is for the UI to handle "Warnings" and "Errors" differently. Based on a note in Tom Hollander's blog, I figured that the "Tag" attribute would be a good way to mark a validation as "Warning" vs. "Error". I've added a PropertyProxyValidator and ValidationSummary to my page, and it is working properly (i.e. Page.IsValid is set to false, ValidationSummary displays the error). I can examine Page.Validators[x].ErrorMessage to get to the MessageTemplate specified in the StringLengthValidator, but I can't figure out how to access the Tag.

If I could get access to the StringLengthValidator object through the PropertyProxyValidator object that would do the trick. Or if the Tag is readily available in some other way that would work.

Of course I could scrape the entire UI, put all the data into my object model, and programmatically use the Validation Block, but then I'd have to manually map the errors to their UI controls and basically re-implement PropertyProxyValidator from scratch. If this is the case I'll probably just hack the error severity into the MessageTemplate and parse it out.

Here's my validator attribute:
[StringLengthValidator(0, RangeBoundaryType.Exclusive, 0, RangeBoundaryType.Ignore, MessageTemplate="Name required.", Tag="Warning")]
public string Name { ... }

- Juan