Here is what I did, and it is being tested perfectly. Since I didn’t know exactly which control you used, I simply used the base text box. I would introduce values such as "July 21, 1983 01:15:00."
JavaScript:
<script type="text/javascript" > function CheckDate(sender, args) { var startDate = new Date(document.getElementById("txtStartDate").value); var finishDate = new Date(document.getElementById("txtFinishDate").value); if (startDate > finishDate) { args.IsValid = false; } else { args.IsValid = true; } } </script>
HTML:
<asp:CustomValidator ID="CustomValidator29" runat="server" ErrorMessage="Finish Date should be greater than the Start Date" ClientValidationFunction="CheckDate" ControlToValidate="txtStartDate"> </asp:CustomValidator> <asp:TextBox id="txtStartDate" runat="server" /> <asp:TextBox id="txtFinishDate" runat="server" />
Here is a table of values and results:
txtStartDate: July 21, 1983 01:15:00
txtEndDate: July 25, 1983 01:15:00
Valid: Yes
txtStartDate: July 25, 1983 01:15:00
txtEndDate: July 21, 1983 01:15:00
Valid: No
txtStartDate: July 21, 1983 01:15:00
txtEndDate: July 21, 1983 06:15:00
Valid: Yes
txtStartDate: July 21, 1983 06:15:00
txtEndDate: July 21, 1983 01:15:00
Valid: No
DanM7 source share