ASP.NET RangeValidator 连最基本的数学都做不了?
我的 ASP.NET RangeValidator 控件出现问题。
我想允许用户输入折扣金额,并且该金额必须为负数(< $0.00)。我想验证文本框中输入的金额是否为负值,因此我在页面标记中包含此内容:
<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" />
并且我尝试在页面呈现之前在代码中动态设置 MaximumValue - 等于我的商品价格的负值。因此,如果商品价格为 69 美元,我想将最小值设置为 - 69 美元:
rvDiscount.MinimumValue = (-1.0m * Price).ToString();
问题是:我不断收到此错误消息:
最大值不能小于0.0 低于最小值 -69.00 rv折扣
WTF?!?!??! 我来自哪里,-69 $ IS 小于 $0 ...... 那么有什么问题呢?
更重要的是:问题的解决方案是什么?
I'm having an issue with my ASP.NET RangeValidator controls.
I want to allow users to enter a discount amount, and this amount must be negative (< $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. So if the item is $69, I want to set the minimum value to - $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
WTF?!?!??! Where I come from, -69 $ IS less than $0 ...... so what's the problem?
And more importantly: what is the solution to the problem??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它不是在尝试做数学,而是在进行字符串比较,因为您没有另外告诉它。尝试添加此属性:
It's not trying to do maths, it's doing a string comparison because you haven't told it otherwise. Try adding this attribute: