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?
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.
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.
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.
What data types do the RangeValidator control support? This control supports five types, i.e., Currency, Date, Double, Integer and String.
The RangeValidator handles validation for multiple types. You should make sure to set the Type to Integer. or what ever is appropriate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With