[英]ASP.NET RangeValidator can't do even the most basic math?
I'm having an issue with my ASP.NET RangeValidator controls. 我的ASP.NET RangeValidator控件存在问题。
I want to allow users to enter a discount amount, and this amount must be negative (< $0.00). 我想允许用户输入折扣金额,此金额必须为负数(<$ 0.00)。 I want to verify that the amount entered in a textbox is a negative value, so I have this in my page markup: 我想验证在文本框中输入的金额是否为负值,所以我在页面标记中有这个:
<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 attempt to set the MinimumValue dynamically in my code before the page gets rendered - to the negative equivalent of my item price. 并且我尝试在页面呈现之前在我的代码中动态设置MinimumValue - 相当于我的商品价格。 So if the item is $69, I want to set the minimum value to - $69: 因此,如果该项目是69美元,我想将最小值设置为 - $ 69:
rvDiscount.MinimumValue = (-1.0m * Price).ToString();
Trouble is: I keep getting this error message: 麻烦的是:我不断收到此错误消息:
The maximum value 0.0 cannot be less than the minimum value -69.00 for rvDiscount 最大值0.0不能小于rvDiscount的最小值-69.00
WTF?!?!??! WTF?!?!?! Where I come from, -69 $ IS less than $0 ...... so what's the problem? 我来自哪里,-69 $ IS不到0美元......那么问题是什么?
And more importantly: what is the solution to the problem?? 更重要的是:问题的解决方案是什么?
It's not trying to do maths, it's doing a string comparison because you haven't told it otherwise. 它不是在尝试做数学,而是在进行字符串比较,因为你没有告诉它。 Try adding this attribute: 尝试添加此属性:
Type="Double"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.