ASP.NET RangeValidator can't do even the most basic math?

I have a problem with ASP.NET RangeValidator controls.

I want to allow users to enter a discount amount, and this amount should be negative (<0.00). I want to verify that the amount entered in the text box is a negative value, so I have this in my page layout:

<asp:TextBox ID="tbxDiscount" runat="server" /> <asp:RangeValidator ID="rvDiscount" runat="server" ControlToValidate="tbxDiscount" MinimumValue="0.0" MaximumValue="0.0" EnableClientScript="true" ErrorMessage="Please enter a negative value for a discount" /> 

and I'm trying to set MinimumValue dynamically in my code before the page is displayed - to the negative equivalent of my product price. Therefore, if the element is $ 69, I want to set the minimum value to $ 69:

 rvDiscount.MinimumValue = (-1.0m * Price).ToString(); 

Problem: I keep getting this error message:

The maximum value of 0.0 cannot be less than the minimum value of -69.00 for rvDiscount

WTF?!?! ??! Where am I from, -69 $ IS less than $ 0 ...... so what's the problem?

And more importantly: what is the solution to the problem?

+6
validation
source share
1 answer

He is not trying to do the math, it is doing string comparisons because you did not say otherwise. Try adding this attribute:

 Type="Double" 
+19
source share

All Articles