Differences between Server-Side Validation and PropertyProxyValidator

Topics: Validation Application Block
May 16, 2008 at 9:18 PM
Hello,

I'm having mixed feelings now about VAB and the PropertyProxyValidator.  Case in point: I'm validating a TextBox that's storing a date value.  I have an AJAX Calendar Extender hooked up to the TextBox to make date selection easier.  This is a required field, so I have a NotNullValidator and a DateRangeValidator setup for the business object.

So to reiterate: I have a business object with a DateTime property, this property gets a value assigned from a TextBox.  The value is a string, because it's accessed through the Text property, but the underlying value is a DateTime value; it just needs converted.  However, because I have a DateRangeValidator hooked up to that TextBox, I get an error saying that the value is a System.String, but it needs to be a DateTime value.  So, how should I handle this?  I want it to work as a DateTime, because I want to be able to make it work for server-side validations as well.  An object can be created on the server side, and using a RegexValidator instead would be incorrect.

How do I handle this?
May 16, 2008 at 9:54 PM
Hi,

The PropertyProxyValidator is a server-side validator, deriving from the standard ASP.NET BaseValidator class. It's just like the built in validators; it just happens to rely on EntLib's validators to validate.

To perform type custom conversion you can attach a handler to the ValueConvert event; there are a few examples in the web site used for the VAB's unit tests that exercise this feature like "Blocks\Validation\Tests\Integration.AspNet.Tests\Web\ValidationWithCustomTypeConversion.aspx".

Hope this helps,
Fernando


bmains wrote:
Hello,

I'm having mixed feelings now about VAB and the PropertyProxyValidator.  Case in point: I'm validating a TextBox that's storing a date value.  I have an AJAX Calendar Extender hooked up to the TextBox to make date selection easier.  This is a required field, so I have a NotNullValidator and a DateRangeValidator setup for the business object.

So to reiterate: I have a business object with a DateTime property, this property gets a value assigned from a TextBox.  The value is a string, because it's accessed through the Text property, but the underlying value is a DateTime value; it just needs converted.  However, because I have a DateRangeValidator hooked up to that TextBox, I get an error saying that the value is a System.String, but it needs to be a DateTime value.  So, how should I handle this?  I want it to work as a DateTime, because I want to be able to make it work for server-side validations as well.  An object can be created on the server side, and using a RegexValidator instead would be incorrect.

How do I handle this?