PropertyComparisonValidator - Failure to retrieve comparand for key

Topics: Validation Application Block
Apr 17, 2008 at 5:03 PM
I'm new to the validation blocks, trying to evaluate their suitability for our environment. I have fund a basic bloker which probably means I'm not using it correctly.

I have followed the documentation sample for the PropertyComparisonValidator ie:

public class AuctionItem
{
public double MinimimumBid
{
get
{
return minimumBid;
}
}
[PropertyComparisonValidator("MinimumBid",
ComparisonOperator.GreaterThanEqual)]
public double CurrentBid
{
get
{
return currentBid;
}
}

// ...
}

And also tried this using the xml config approach. However either way I get this type of message...

Failure to retrieve comparand for key "ValidationAmountMax": The property name "ValidationAmountMax" is not mapped to validators in the naming context..

In this case ValidationAmountMax is the property I'm comparing to (equiv MinimumBid), and the attribute is applied to an Amount property which has a text box in the aspx page:

<cc1:PropertyProxyValidator ID="txtAmountValidator" runat="server" ControlToValidate="txtAmount"
PropertyName="Amount" RulesetName="RuleSetStep2"
SourceTypeName="ValidationQuickStart.BusinessEntities.BuyInstruction"></cc1:PropertyProxyValidator>

What am I doing wrong?

Thanks

Ray
Apr 17, 2008 at 9:02 PM
Hi Ray,

I see that you're using the ASP.NET integration. When you're using it, and because of where validation happens in the lifecycle of an ASP.NET request (http://msdn2.microsoft.com/en-us/library/ms178472.aspx), validation will occur before your business object gets its values set; only the values in the validated controls can be validated. In this scenario, the validations you specify on a class are really a specification of how you want the controls' values to be validated, and in this case it looks like one of the properties involved in this comparison is not mapped to any control so the validation fails.

You will need to keep the other value in a control for this to work, even if its not intended to be modified by the user.

Hope this helps,
Fernando
Apr 18, 2008 at 8:25 AM

Thanks Fernando,

I understand what it is doing now – disappointing as it isn’t what I want – but you have saved me lots of trial an error.

As it happens, my business object is populated in the Page_Load, so does in fact have the properties set when the validation runs (assuming the sequence in the link applies to these validators). What I’m trying to achieve is validating a value input in step 2 of a wizard dialog, when the value range depends on a property set in step 1 of the wizard. What would the approach be for doing this in an asp.net environment?

Your help is much appreciated

Thanks

Ray
Feb 2, 2009 at 8:48 PM
Did you every figure this out, if so how? I see that you're using the ASP.NET integration. Is this not possible with ASP.Net integration? I have a DateOfDeath that needs to be bigger than the DateOfBirth and I am getting the following error message:
Failure to retrieve comparand for key "DateOfBirth": The property name "DateOfBirth" is not mapped to validators in the naming context.

 

<entLibValidator:PropertyProxyValidator ID="PropertyProxyValidatorDateOfDeath"

 

 

runat="server" ControlToValidate="TextBoxDateOfDeath" Display="Dynamic"

 

 

SetFocusOnError="true" CssClass="validatormessage" PropertyName="DateOfDeath"

 

 

SourceTypeName="Model.DeceasedInfo" SpecificationSource="Attributes"></entLibValidator:PropertyProxyValidator>

 

Feb 2, 2009 at 8:56 PM
Fernando - what do you mean by this - You will need to keep the other value in a control for this to work, even if its not intended to be modified by the user.

My I would like to compare my DateOfDeath with my DateOfBirth using the VAB my  DateOfBirth is entered in a textbox by the user so is the DateOfDeath but the validation fails. Can you help me out a little more, thanks.

Failure to retrieve comparand for key "DateOfBirth": The property name "DateOfBirth" is not mapped to validators in the naming context.

 

<entLibValidator:PropertyProxyValidator ID="PropertyProxyValidatorDateOfDeath"

runat="server" ControlToValidate="TextBoxDateOfDeath" Display="Dynamic"

 SetFocusOnError="true" CssClass="validatormessage" PropertyName="DateOfDeath"

SourceTypeName="Model.DeceasedInfo" SpecificationSource="Attributes"></entLibValidator:PropertyProxyValidator>

Feb 3, 2009 at 6:23 AM
Hi,

I tried this one on a pure config and not by the attributes, but i still repro your error, so, i solved the error by adding another propertyproxyvalidator for the DateOfBirth.


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Feb 4, 2009 at 6:35 PM
Edited Feb 4, 2009 at 6:42 PM
Thanks for the reply. So I do need another propertyproxyvalidator for the DateOfBirth. 

I added this code to the DateOfBirth and it is working. Both textboxes DateOfBrith and DateOfDeath have now a propertyproxyvalidator. What about the attributes for the property, there is none. Do I have to also add an attribute for the DateOfBirth even though it would never be used? Still a little confused.

 

<entLibValidator:PropertyProxyValidator ID="PropertyProxyValidatorDateOfBirth"

 

 

runat="server" ControlToValidate="TextBoxDateOfBirth" Display="Dynamic"

 

 

SetFocusOnError="true" CssClass="validatormessage" PropertyName="DateOfBirth"

 

 

SourceTypeName="Model.DeceasedInfo" SpecificationSource="Attributes"></entLibValidator:PropertyProxyValidator>

 

Feb 5, 2009 at 2:39 AM
No you dont have to. Since you are just validating the DateOfDeath, I tried it, and it works fine. I just added attributes on the DateOfDeath.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com