PropertyComparisonValidator and null date

Topics: Validation Application Block
Jul 22, 2009 at 1:06 PM

I would like to compare a start date being less than or equal to an end date but the end date can be null.  If the end date is null the PropertyComparisonValidator continues with the validation and states the Start Date is greater than End Date.  I do not want a comparison if the end date is null

public DateTime StartDate { get; set; }

[NotNullValidator(Ruleset = "RuleSetFields",Negated=true)]

[PropertyComparisonValidator("StartDate", ComparisonOperator.GreaterThanEqual,
            Ruleset = "RuleSetFields", MessageTemplate = "Start date cannot be greater than End date.")]
public DateTime? EndDate { get; set; }

1) Tried the above

2) Tried the above without the negated=true

3) Tried without the Composition and Not Null attributes.

Thank you in Advance.

Jul 23, 2009 at 2:36 AM

Change the CompositionType to Or instead of And.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.