asp.netrangevalidator

asp:RangeValidator validates on textChanged in TextBox


I have the following <asp:RangeValidator>:

<asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="TextBoxInterestRate" ErrorMessage="Enter value greater than zero!" ForeColor="Red" MaximumValue="100000" MinimumValue="0.10"></asp:RangeValidator>

If the page is loaded for the first time, then the RangeValidator works perfectly. But, I have a Button in my project, which on clicking, loads the TextBox with a certain value (always within the range 0.1 - 100000). Now if I edit the value in the TextBox from the keyboard, the RangeValidator is popping up the ErrorMessage even when the new value/edited value is well within the range.

For example, say the value that came into the TextBox on clicking the Button is 8.5. Now, if I change it to 10.25, the ErrorMessage is popping up. What should I do?

I am working on ASP.NET WebForms.


Solution

  • I found the solution on MSDN RangeValidator Control Documentation. All I needed to do was to add Type = "Double" to the statement and it worked perfectly.

    <asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="TextBoxInterestRate" ErrorMessage="Enter value greater than zero!" ForeColor="Red" Type="Double" MaximumValue="100000" MinimumValue="0.10"></asp:RangeValidator>

    The available DataTypes are:

    Currency, Date, Double, Integer, String