I am trying to validate a start date and finish date so that if a finish date entered by a user is before the start date it will throw up an error. I am doing this using JavaScript and the custom validator but get a runtime error saying 'CheckDate is undefined'.
I think this shouldn't be hard to solve as the code looks ok think I'm just missing something.
Any help would be great.
Here is my JavaScript, it is in script tags just haven't copied them over
function CheckDate(sender, args) {
if (new date (document.getElementById("txtstartdate").value)
> new (document.getElementById("TxtFinish").value)) {
args.IsValid = false;
return;
}
args.IsValid = true;
}
Here is the validation on my FinishDate control
<asp:CustomValidator ID="CustomValidator29" runat="server"
ErrorMessage="Finish Date should be greater than the Start Date" ClientValidationFunction="CheckDate"></asp:CustomValidator>
Need any more info ask away :).
You can simply use a CompareValidator!
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="txtStartDate" ControlToValidate="txtEndDate"
Display="Static" ErrorMessage="'End Date' must not be earlier than 'From Date'" Text="*"
Operator="GreaterThanEqual" SetFocusOnError="True" Type="Date"
ValidationGroup="SearchGroup">