开发者

formatting an asp:TextBox with thousand and decimal separators

开发者 https://www.devze.com 2023-02-03 23:13 出处:网络
I have done this many times in PHP using JS but being new to webforms I\'m really struggling on this one...

I have done this many times in PHP using JS but being new to webforms I'm really struggling on this one...

OKay, on my form I have an "asp:TextBox" that I want the user to enter an amount of money into.

What I would like is once the user moves out of the "asp:TextBox", I would like it formatted like ###,###,###.## for display purposes. I dont need the currency symbol.

Can anyone give 开发者_Go百科any guidance on how to do this and also is the formatting submitted along with the value on submit as standard or is that stripped away and only used for user display purposes?

Thanks

Paul


You can add client-side functionality to webform controls by adding attributes to them before they get rendered. You can add a property to the textbox in your code:

myTextbox.Attributes.Add("onblur", "myJavascriptFormattingFunction();");

You can take a look at this article for other methods of linking webcontrols to javascript.

Whatever value is in the textbox itself is what will be submitted, so if you add commas and whatnot, then they will be submitted.

0

精彩评论

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

关注公众号