开发者

Can I get the ASP.NET RangeValidator an onblur/onfocus events to play nice with each other?

开发者 https://www.devze.com 2022-12-13 16:58 出处:网络
I have a textbox for entering a curr开发者_如何学编程ency amount, with a RangeValidator control making sure the value entered is between 1 and 99999999.99.

I have a textbox for entering a curr开发者_如何学编程ency 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.


Just change the RangeValidator's Type to currency (Type="Currency") and it will accept commas and any other currency symbols.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号