简体   繁体   English

8不小于或等于30?

[英]8 is not less than or equal to 30?

Alright, I've got a RangeValidator : 好吧,我有一个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. 正如您所看到的,最小值为1,最大值为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. 正如您所看到的,我已将客户端ID设置为静态,因此它可以很好地找到控件。


That hidden field is populated by this JavaScript method when one of the two dates change: 当两个日期之一发生变化时,此隐藏字段由此JavaScript方法填充:

$('.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. 当调用Page_ClientValidate时,我调试它以确保验证器按预期触发,它是,并且它具有我期望的值。 When the minimum is checked it's grabbing 1 ... and when that is compared to a value of 8 ... it's evaluating as expected ... 8 is greater than or equal to 1. 当检查到最小值时,它会抓取1 ...并且当它与值8进行比较时...它正在按预期进行评估... 8大于或等于1。

However, when the maximum is checked, even though it's grabbing 30 for the maximum ... when it's compared to a value of 8 ... the expression that says 8 is less than or equal to 30 is being evaluated to false. 但是,当检查最大值时,即使它最大值为30 ......当它与值8相比时......表示8小于或等于30的表达式被评估为假。


I really hope somebody can help me out here! 我真的希望有人可以帮助我!

How in the world is 8 not less than 30 here? 这个世界上8个不少于30个?

您在RangeValidator上缺少Type="Integer"

Type="Integer"添加到范围验证器

You need to set the type on the RangeValidator : 您需要在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.com/en-us/library/system.web.ui.webcontrols.basecomparevalidator.type.aspx 相关的MSDN文档: http//msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.basecomparevalidator.type.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM