function compareError(sender, args) {
var dateStart = $("#<%=txtStartTime.ClientID %>").val().replace(/\-/g, "\/"); var dateEnd = $("#<%=txtEndTime.ClientID %>").val().replace(/\-/g, "\/"); if (dateStart.length > 0 && dateEnd.length > 0) { if (dateStart > dateEnd) { args.IsValid = false; } else { args.IsValid = true; } } else { args.IsValid = true; }}
<asp:CustomValidator ID="CustomValidator1" runat="server" ClientValidationFunction="compareError" ForeColor="red" ErrorMessage="截止日期大于起始日期!"></asp:CustomValidator>