I have a start date and end date field in a form. I have specified format for calender extender. since then, the compare validator is not working. It is always displaying the error message. Please help. I need to show the date in the format "Fri 04 May 2012".
Start date field:
<asp:TextBox ID="txtStartDate" ReadOnly="true" runat="server"
CssClass="textBoxWidth TPRValue" Text='<%#DataBinder.Eval(Container.DataItem, "StartDate", "{0: ddd MM dd, yyyy}")%>'>
</asp:TextBox>
<asp:ImageButton ID="imgBtnStartDate" runat="server" ImageUrl="~/Common/Images/Calendar.GIF" CausesValidation="false" ImageAlign="AbsMiddle" />
<ajax:CalendarExtender ID="StartDateCalendar" TargetControlID="txtStartDate" PopupButtonID="imgBtnStartDate" runat="server"
Format="ddd MM dd, yyyy">
</ajax:CalendarExtender>
<asp:CompareValidator ID="startDateCompareValidator" runat="server" ControlToValidate="txtStartDate" ControlToCompare="txtEndDate" Enabled="true"
Type="Date" Display="Dynamic" Operator="LessThanEqual"
Text="Startdate should be <= enddate">
</asp:CompareValidator>
EndDate field:
<asp:TextBox ID="txtEndDate" ReadOnly="true" runat="server"
CssClass="textBoxWidth TPRValue" Text='<%#DataBinder.Eval(Container.DataItem, "EndDate", "{0: ddd MM dd, yyyy}")%>'>
</asp:TextBox>
<asp:ImageButton ID="imgBtnEndDate" runat="server" ImageUrl="~/Common/Images/Calendar.GIF" CausesValidation="false" ImageAlign="AbsMiddle" />
<ajax:CalendarExtender ID="EndDateCalendar" TargetControlID="txtEndDate" PopupButtonID="imgBtnEndDate" runat="server"
Format="ddd MM dd, yyyy">
</ajax:CalendarExtender>
Compare validator:
<asp:CompareValidator ID="startDateCompareValidator" runat="server" ControlToValidate="txtStartDate"
ControlToCompare="txtEndDate" Enabled="true" Type="Date" Display="Dynamic" Operator="LessThanEqual"
Text="Startdate should be <= enddate">
</asp:CompareValidator>
See Question&Answers more detail:os