Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net range validator on textbox

Tags:

c#

asp.net

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?

like image 705
Jordan Foreman Avatar asked Jan 11 '12 20:01

Jordan Foreman


People also ask

How do you use a range validator?

Step 1 – Open Visual Studio –> Create a new empty Web application. Step 2 – Create a new web page and design web form with three textbox control along with button control. Step 3 – Drag and drop RangeValidator control from Toolbox. Step 5 – Set MaximumValue and MinimumValue Property.

Which of the following is used to specify the range in range validator control?

The RangeValidator control uses four key properties to perform its validation. The ControlToValidate property contains the input control to validate. The MinimumValue and MaximumValue properties specify the minimum and maximum values of the valid range. The BaseCompareValidator.

What is range validation?

Range Validation applies to ensuring that the user input value is within the specified range. We can use Range Validation on both strings and numbers. He will use Range Validation on the number.

Which type can support in RangeValidator?

What data types do the RangeValidator control support? This control supports five types, i.e., Currency, Date, Double, Integer and String.


1 Answers

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

like image 90
Andrew Barber Avatar answered Oct 22 '22 07:10

Andrew Barber