我可以让 ASP.NET RangeValidator 与 onblur/onfocus 事件相互配合吗?
我有一个用于输入货币金额的文本框,并使用 RangeValidator 控件确保输入的值在 1 到 99999999.99 之间。
该字段还有一个“onblur”事件,该事件会触发一些 JavaScript 以使用逗号和小数点格式化输入(例如 12455 -> 12,455.00)。还有一个“onfocus”事件可以反转“onblur”效果,将值重新设置为可编辑格式(例如 12,455.00 -> 12455.00。
我的问题是 RangeValidator 不喜欢带有逗号的格式化值,随后失败 有没有办法
解决这个问题?我希望能够对值进行范围检查,但在文本框没有焦点时仍然显示它的格式,我意识到 CustomValidator 可能可以工作,但我希望。让它与 RangeValidator 一起使用。
I have a textbox for entering a currency amount, with a RangeValidator control making sure the value entered is between 1 and 99999999.99.
The field also has an “onblur” event that fires off some JavaScript to format the input with commas and a decimal point (e.g. 12455 -> 12,455.00). There's also a "onfocus" event that reverses the "onblur" effect, putting the value back into an editable format (e.g. 12,455.00 -> 12455.00.
My problem is the RangeValidator doesn't like the formatted value with the commas and subsequently fails on the validation.
Is there a way to get around that? I want to be able to range check the value, yet still present it formatted when the textbox doesn't have focus. I realize that a CustomValidator could probably work, but I was hoping to get this to work with the RangeValidator.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将 RangeValidator 的类型更改为货币 (Type="Currency"),它将接受逗号和任何其他货币符号。
Just change the RangeValidator's Type to currency (Type="Currency") and it will accept commas and any other currency symbols.
简单的。不要使用 Range 验证器(用于客户端验证的服务器端控件),而是在 Javascript 的 OnBlur 方法中添加几行代码,这样会更好。
或
使用类似下面的链接
http://www.java2s。 com/Code/ASP/Validation-by-Control/UseJavascriptandaspvalidationcontroltogetherVBnet.htm
Simple. Instead of Using the Range validator (a sever side control for client side validation), add few lines of code in the OnBlur method of the Javascript which would be better.
or
Use something like below link
http://www.java2s.com/Code/ASP/Validation-by- Control/UseJavascriptandaspvalidationcontroltogetherVBnet.htm