I'm not sure whether this is strictly a javascript question or a question peculiar to this control. Anyway, feel free to re-direct me if you think this is appropriate. I'm still learning ASP.Net so please be nice
Anyway, here is the problem: My ASP (this is .Net v1.1 BTW) page has two TextBox controls that contain date values (in short form). Bear in mind that in Australia, the date format in common use is the British format, DD/MM/YYYY.
I have two separate RangeValidator controls associated with these two TextBox controls. The minimum value is set at design time in Visual Studio 2003 and the maximum value of these RangeValidator controls is set in the Page_Load event to today's date.
The two controls are to display a hire date and a birth date. The birth date is displayed as 1/09/1958 (i.e. 1st of September 1958) and the hire date is displayed as 5/03/1994 (i.e. 5th of March 1994). The minimum value for both RangeValidation controls is set as 01/01/1900. The maximum range is then set (today) as 14/11/2005.
When I hit my Update button which causes validation, the hire date value is said to be out of range. This behaviour is in WebUIValidation.js. For the purposes of illustration, I have copied a brief extract of the relevant functions from the javascript file below.
RangeValidatorEvaluateIsValid checks that it is within the range by calling ValidatorCompare:
function RangeValidatorEvaluateIsValid(val) {
var value = ValidatorGetValue(val.controltovalidate);
if (ValidatorTrim(value).length == 0)
return true;
return (ValidatorCompare(value, val.minimumvalue, "GreaterThanEqual", val) &&
ValidatorCompare(value, val.maximumvalue, "LessThanEqual", val));
}
The problem is when ValidatorCompare is asked to evaluate the comparison if hire is less than or equal to today's date (i.e. 14/11/2005 in this example).
function ValidatorCompare(operand1, operand2, operator, val) {
var dataType = val.type;
var op1, op2;
if ((op1 = ValidatorConvert(operand1, dataType, val)) == null)
return false;
if (operator == "DataTypeCheck")
return true;
if ((op2 = ValidatorConvert(operand2, dataType, val)) == null)
return true;
switch (operator) {
case "NotEqual":
return (op1 != op2);
case "GreaterThan":
return (op1 > op2);
case "GreaterThanEqual":
return (op1 >= op2);
case "LessThan":
return (op1 < op2);
case "LessThanEqual":
return (op1 <= op2); [highlight]This returns false[/highlight]
default:
return (op1 == op2);
}
}
Curiously, if I put a leading zero back into the date string (i.e. 05/03/1994) it validates correctly but I don't understand why the birth date validated correctly.
I don't know what I'm doing wrong but I would appreciate any guidance.
Anyway, here is the problem: My ASP (this is .Net v1.1 BTW) page has two TextBox controls that contain date values (in short form). Bear in mind that in Australia, the date format in common use is the British format, DD/MM/YYYY.
I have two separate RangeValidator controls associated with these two TextBox controls. The minimum value is set at design time in Visual Studio 2003 and the maximum value of these RangeValidator controls is set in the Page_Load event to today's date.
The two controls are to display a hire date and a birth date. The birth date is displayed as 1/09/1958 (i.e. 1st of September 1958) and the hire date is displayed as 5/03/1994 (i.e. 5th of March 1994). The minimum value for both RangeValidation controls is set as 01/01/1900. The maximum range is then set (today) as 14/11/2005.
When I hit my Update button which causes validation, the hire date value is said to be out of range. This behaviour is in WebUIValidation.js. For the purposes of illustration, I have copied a brief extract of the relevant functions from the javascript file below.
RangeValidatorEvaluateIsValid checks that it is within the range by calling ValidatorCompare:
function RangeValidatorEvaluateIsValid(val) {
var value = ValidatorGetValue(val.controltovalidate);
if (ValidatorTrim(value).length == 0)
return true;
return (ValidatorCompare(value, val.minimumvalue, "GreaterThanEqual", val) &&
ValidatorCompare(value, val.maximumvalue, "LessThanEqual", val));
}
The problem is when ValidatorCompare is asked to evaluate the comparison if hire is less than or equal to today's date (i.e. 14/11/2005 in this example).
function ValidatorCompare(operand1, operand2, operator, val) {
var dataType = val.type;
var op1, op2;
if ((op1 = ValidatorConvert(operand1, dataType, val)) == null)
return false;
if (operator == "DataTypeCheck")
return true;
if ((op2 = ValidatorConvert(operand2, dataType, val)) == null)
return true;
switch (operator) {
case "NotEqual":
return (op1 != op2);
case "GreaterThan":
return (op1 > op2);
case "GreaterThanEqual":
return (op1 >= op2);
case "LessThan":
return (op1 < op2);
case "LessThanEqual":
return (op1 <= op2); [highlight]This returns false[/highlight]
default:
return (op1 == op2);
}
}
Curiously, if I put a leading zero back into the date string (i.e. 05/03/1994) it validates correctly but I don't understand why the birth date validated correctly.
I don't know what I'm doing wrong but I would appreciate any guidance.