简体   繁体   English

文本框上的asp.net范围验证器

[英]asp.net range validator on textbox

I have an asp:textbox with both required and range validators attached to it, where the code looks like this: 我有一个asp:textbox附带了必需和范围验证器,代码如下所示:

ASP: ASP:

<asp:TextBox ID="textBox1" runat="server" CausesValidation="true"></asp:TextBox>
<asp:RangeValidator ID="rangeValidator1" runat="server" ControlToValidate="textBox1" MaximumValue="1" MinimumValue="0"
     ValidationGroup="valid" ForeColor="Red" ErrorMessage="Out of Range" />
<asp:RequiredFieldValidator ID="requiredValidator1" runat="server" ControlToValidate="textBox1"
     ValidationGroup="valid" ForeColor="Red" ErrorMessage="Cannot be blank" />

And when the page is dynamically loaded (after a quick callback), I have code that is supposed to change the MaximumValue of the RangeValidator to more specific value. 当页面被动态加载时(在快速回调之后),我的代码应该将RangeValidator的MaximumValue更改为更具体的值。 Here is the code for that: 这是代码:

rangeValidator1.MaximumValue = GetMaxValue(params).ToString();

Now, I have set a breakpoint, and rangeValidator1.MaximumValue is being set correctly, however, when the page loads, and I look at the compiled client side javascript, it appears that the maximum value is still only 1. 现在,我已经设置了断点,并且正确设置了rangeValidator1.MaximumValue ,但是,当页面加载时,我查看编译的客户端javascript,看起来最大值仍然只有1。

What confuses me more is that any integer typed in will pass, as long as the first digit is a '1'. 更让我困惑的是,只要第一个数字是'1',任何输入的整数都会通过。 So if the maxValue is supposed to be something like "1234567", "1" will match, as will "12345678910". 因此,如果maxValue 应该类似于“1234567”,则“1”将匹配,“12345678910”也将匹配。 But "2" will not. 但“2”不会。 Nor will "3000" or "46000". “3000”或“46000”也不会。

Has anyone else had a similar issue with RangeValidators on Textboxes? 还有其他人在Textboxes上有类似的RangeValidators问题吗?

The RangeValidator handles validation for multiple types. RangeValidator处理多种类型的验证。 You should make sure to set the Type to Integer. 您应该确保将Type设置为Integer。 or what ever is appropriate. 或者什么是合适的。

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

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