[RESOLVED]validating a CalendarExtender date against another CalendarExtender date

I have 2 CalendarExtenders and would like the 2nd

CalendarExtender date to be ‘GreaterThanEqual’ to the first one.

At the moment I get my validation error popping up for all dates entered!

Here’s what i have:

first text Box

<asp:TextBox ID="txtEnrolmentDate" runat="server" MaxLength="10"></asp:TextBox>  &nbsp;

2nd text box

   <asp:TextBox ID="txtDefferralDate" runat="server" MaxLength="10"></asp:TextBox> 


  <asp:CompareValidator ID=" " 
                            ErrorMessage="Deferral date cannot be before the enrolment date"
                             Operator="GreaterThanEqual" ValueToCompare="txtEnrolmentDate" 

is it to do with the above validation being a string and its trying to compare it with a date?
But when I set my validator type to a ‘date’ it crashes – with this error:
ValueToCompare property of " " cannot be converted to type date.

So, do I need to create another box/label and convert my textbox: ‘txtEnrolmentDate’ into a date value and use this to validate against?
Or is there a quicker way of converting this string into a date within the validator:
‘cvDeferralDate’ ?

<asp:CompareValidator ID="cmpStartDate" runat="server"
                        ErrorMessage="Start date cannot be less than today's date" 
                        Operator="GreaterThanEqual" Type="Date"

thanks for the reply, but…

If I put type="Date", the page crashes with this error:
ValueToCompare property of " " cannot be converted to type date.

- due to txtDeferralDate – being in a textbox

Check this its Work for me fine

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1">
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
             <asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="TextBox2">

            <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="CompareValidator" ControlToCompare="TextBox1" ControlToValidate="TextBox2" Type="Date" Operator="GreaterThanEqual"></asp:CompareValidator>
                <asp:Button ID="Button1" runat="server" Text="Button" />


your code does indeed work but I think i must have something else going on, I’ve got other validation and having trouble getting it to work with other validation around it.


Leave a Reply