[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> 

Validation:

  <asp:CompareValidator ID=" " 
                            runat="server" 
                            ErrorMessage="Deferral date cannot be before the enrolment date"
                          ControlToValidate="txtDefferralDate" 
                            Display="Dynamic" 
                              SetFocusOnError="True"
                             Operator="GreaterThanEqual" ValueToCompare="txtEnrolmentDate" 
                            ></asp:CompareValidator>

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’ ?
thanks.

<asp:CompareValidator ID="cmpStartDate" runat="server"
                        ControlToValidate="txtDefferralDate"
                        ErrorMessage="Start date cannot be less than today's date" 
                        Operator="GreaterThanEqual" Type="Date"
ValueToCompare="txtEnrolmentDate"></asp:CompareValidator>&nbsp;

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:CalendarExtender>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
             <asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="TextBox2">
            </asp:CalendarExtender>


         
       
            <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" />

thanks,

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