Hi,
My first suggestion is use compare validator its work super
set
ControlToValidate= txtToDate
ControlToCompare =txtFromDate
setfocusonerror=true
Operator =GreaterThan
Type=date
its work superbly
otherwise u use following javascript
function CheckValidDate(fromDate, toDate) {
var chk = /^(((((0[1-9])|(1\d)|(2[0-8]))\/((0[1-9])|(1[0-2])))|((31\/((0[13578])|(1[02])))|((29|30)\/((0[1,3-9])|(1[0-2])))))\/((20[0-9][0-9])|(19[0-9][0-9])))|((29\/02\/(19|20)(([02468][048])|([13579][26]))))$/
if (fromDate.value != "" && toDate.value != "" && toDate != 'T') {
if (chk.test(fromDate.value) && chk.test(toDate.value)) {
if (FormatDate(fromDate.value) > FormatDate(toDate.value)) {
alert('From Date shouldnt be greater than To Date');
return false;
}
else
return true;
}
else {
alert('Invalid Date');
return false;
}
}
else {
if (chk.test(fromDate.value)) {
if (FormatDate(fromDate.value) > FormatDate(document.getElementById("hdnTodayDate").value)) {
alert('Selected Date should be less than or equal to current date');
return false;
}
else
return true;
}
else {
alert('Invalid Date')
return false;
}
}
}
function FormatDate(val) {
var tmpDate = val.split("/");
var DD = tmpDate[0];
var MM = tmpDate[1];
var YYYY = tmpDate[2];
var fDate = new Date(MM + "/" + DD + "/" + YYYY);
return fDate;
}
calling of function
on pageload event
btnSave.Attributes["onClick"]="return CheckValidDate(txtfromDate.Text, toDate.Text);