javascript - 8 is not less than or equal to 30? - Stack Overflow

Alright, I've got a RangeValidator:<asp:RangeValidator ID="DateRangeValidator" runat=

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 badges
Add a ment  | 

3 Answers 3

Reset to default 10

You'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

相关推荐

  • javascript - 8 is not less than or equal to 30? - Stack Overflow

    Alright, I've got a RangeValidator:<asp:RangeValidator ID="DateRangeValidator" runat=

    8天前
    60

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信