Alright, I've got a RangeValidator
:
<asp:RangeValidator ID="DateRangeValidator" runat="server" ControlToValidate="DateRange"
ErrorMessage="The date range must be at least 1 day, not more than 30, and neither date can be greater than today's date."
EnableClientScript="true" MinimumValue="1" MaximumValue="30" CssClass="errortext span9 offset2"
Display="Dynamic" />
And as you can see the minimum is 1 and the maximum is 30.
That is validating a hidden field (it's visible at the moment cause I'm testing):
<asp:TextBox ID="DateRange" runat="server" ClientIDMode="Static" />
And as you can see I've set the client ID to be static so it's finding the control just fine.
That hidden field is populated by this JavaScript method when one of the two dates change:
$('.datepicker').change(function () {
var startDate = new Date($('#StartDate').val());
var endDate = new Date($('#EndDate').val());
if (startDate > Date() || endDate > Date()) {
$('#DateRange').val(-1);
}
else {
var nDifference = endDate - startDate;
var one_day = 1000 * 60 * 60 * 24;
$('#DateRange').val(Math.round(nDifference / one_day) + 1);
}
Page_ClientValidate(null);
});
And this method is working perfectly from the perspective of setting the correct number of days difference.
When the Page_ClientValidate
is called I've debugged it to ensure the validator is firing as expected, and it is, and it has the values I would expect. When the minimum is checked it's grabbing 1 ... and when that is pared to a value of 8 ... it's evaluating as expected ... 8 is greater than or equal to 1.
However, when the maximum is checked, even though it's grabbing 30 for the maximum ... when it's pared to a value of 8 ... the expression that says 8 is less than or equal to 30 is being evaluated to false.
I really hope somebody can help me out here!
How in the world is 8 not less than 30 here?
Alright, I've got a RangeValidator
:
<asp:RangeValidator ID="DateRangeValidator" runat="server" ControlToValidate="DateRange"
ErrorMessage="The date range must be at least 1 day, not more than 30, and neither date can be greater than today's date."
EnableClientScript="true" MinimumValue="1" MaximumValue="30" CssClass="errortext span9 offset2"
Display="Dynamic" />
And as you can see the minimum is 1 and the maximum is 30.
That is validating a hidden field (it's visible at the moment cause I'm testing):
<asp:TextBox ID="DateRange" runat="server" ClientIDMode="Static" />
And as you can see I've set the client ID to be static so it's finding the control just fine.
That hidden field is populated by this JavaScript method when one of the two dates change:
$('.datepicker').change(function () {
var startDate = new Date($('#StartDate').val());
var endDate = new Date($('#EndDate').val());
if (startDate > Date() || endDate > Date()) {
$('#DateRange').val(-1);
}
else {
var nDifference = endDate - startDate;
var one_day = 1000 * 60 * 60 * 24;
$('#DateRange').val(Math.round(nDifference / one_day) + 1);
}
Page_ClientValidate(null);
});
And this method is working perfectly from the perspective of setting the correct number of days difference.
When the Page_ClientValidate
is called I've debugged it to ensure the validator is firing as expected, and it is, and it has the values I would expect. When the minimum is checked it's grabbing 1 ... and when that is pared to a value of 8 ... it's evaluating as expected ... 8 is greater than or equal to 1.
However, when the maximum is checked, even though it's grabbing 30 for the maximum ... when it's pared to a value of 8 ... the expression that says 8 is less than or equal to 30 is being evaluated to false.
I really hope somebody can help me out here!
How in the world is 8 not less than 30 here?
Share Improve this question asked Nov 23, 2012 at 13:17 Mike PerrenoudMike Perrenoud 68k32 gold badges166 silver badges238 bronze badges3 Answers
Reset to default 10You're missing a Type="Integer"
on your RangeValidator
.
Add Type="Integer"
to your range validator
You need to set the type on the RangeValidator
:
<asp:RangeValidator ID="DateRangeValidator" runat="server" ControlToValidate="DateRange"
ErrorMessage="The date range must be at least 1 day, not more than 30, and neither date can be greater than today's date."
EnableClientScript="true" MinimumValue="1" MaximumValue="30" CssClass="errortext span9 offset2"
Display="Dynamic"
Type="Integer" />
Relevant MSDN docs: http://msdn.microsoft./en-us/library/system.web.ui.webcontrols.baseparevalidator.type.aspx
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744214481a4563485.html
评论列表(0条)