CoolDev2014
asked on
asp.net, c#
I have two textboxes using for dates. like begin date and end date.
How can I validate begin date must be earlier than end date in code behind (c#)?
How can I validate begin date must be earlier than end date in code behind (c#)?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<asp:CompareValidator id="cvtxtStartDate" runat="server" ControlToCompare="txtStartDate" cultureinvariantvalues="true" display="Dynamic" enableclientscript="true" ControlToValidate="txtFinishDate" ErrorMessage="Start date must be earlier than finish date" type="Date" setfocusonerror="true" Operator="GreaterThanEqual" text="Start date must be earlier than finish date"></asp:CompareValidator>
But I would suggest to make validation from client side using javascript code as per belowif (Date.parse(fromDate) > Date.parse(toDate)) {
alert("Invalid Date Range!\nStart Date cannot be after End Date!")
return false;
}
ASKER