15

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?

5
  • 1
    textbox1 does not appear to be in the same ValidationGroup and the id is textBox1 (note the capital B) Is that just a typo here? Commented Jan 11, 2012 at 20:50
  • 1
    Also, doesn't RangeValidator have a Type field? Commented Jan 11, 2012 at 20:51
  • in regards to your first comment, sorry, that was a typo. I changed the ids when I copied the code over to SO so that it was easier to read. They do match up. Commented Jan 11, 2012 at 20:59
  • 1
    and in regards to your second comment...adding Type="Integer" fixed it right up. Thanks. If you want to post that as the answer...I'll accept it. Commented Jan 11, 2012 at 21:02
  • Your question is answered here: stackoverflow.com/q/6962947/310112 Commented Jan 11, 2012 at 21:06

1 Answer 1

21

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.