简体   繁体   中英

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:

<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. 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.

What confuses me more is that any integer typed in will pass, as long as the first digit is a '1'. So if the maxValue is supposed to be something like "1234567", "1" will match, as will "12345678910". But "2" will not. Nor will "3000" or "46000".

Has anyone else had a similar issue with RangeValidators on Textboxes?

The RangeValidator handles validation for multiple types. You should make sure to set the Type to Integer. or what ever is appropriate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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