Попробуйте использовать пользовательский валидатор:
<asp:CustomValidator ID="valCustmCheckDate" runat="server" ErrorMessage="The date difference should not be greater than 100 days" ForeColor="Red" ValidationGroup="LoginUserAdd" ClientValidationFunction="CompareStartAndEndDate"></asp:CustomValidator>
Вызовите следующую функцию в javascript:
function CompareStartAndEndDate(sender,args) {
var txtFromExpiryDate = document.getElementById('<%=txtFromDate.ClientID %>');//dd/mm/yyyy format
var txtToExpiryDate = document.getElementById('<%=txtToDate.ClientID %>');//dd/mm/yyyy format
var a = txtFromDate.value.split('/');
var b = txtToDate.value.split('/');
var FromDate = new Date(a[2], a[1] - 1, a[0]);
var ToDate = new Date(b[2], b[1] - 1, b[0]);
var newFromDate =FromDate.getTime();
var newToDate=ToDate.getTime();
var dateDiffInMilliseconds= newToDate-newFromDate;
var dateDiffInDays=dateDiffInMilliseconds/(1000 * 60 * 60 * 24)
if (dateDiffInDays>100 ) {
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
Надеюсь, это поможет вам ...