I have this textbox that should show currency values to 2 decimal numbers. I would like to do using the "Text" property of textboxes. Is that possible?
<asp:TextBox ID="txtImponibile" runat="server" Width="120px" Enabled="False" ></asp:TextBox>
Thanks.
Yes you can:
string.Format("$ {0:#,##0.00}", double.Parse(textBox1.Text));
In this case it is globally ineffective, for it will display the $ sign, use commma (,) for a thousand separator and point/dot (.) for decimal. (You could change the currency symbol, but the separators will not change. Take into account that if the language you are developing for interchanges the separator dot for thousands and comma for decimals. Ex: Spanish)
string.Format(CultureInfo.CurrentCulture,"{0:C}", double.Parse(textBox1.Text));
This will give you currency, however this case depends on the culture you set up for the website. I know how to configure it by page: The first line of HTML code in the aspx file.
<%@ Page Language="C#" AutoEventWireup="true" Culture="es-HN" UICulture="es-HN" CodeBehind="yourpage.aspx.cs" Inherits="yoursite.yourpage" %>
There is a way to configure it in the web.config file but I do not know how. I encourage you to look for it. So far, I just include [Culture="es-HN" UICulture="es-HN"] on each page and it works. By the way, those values are for Honduras, so if you need other culture values look for them here: www.csharp-examples.net/culture-names/.
You can wrap TextBox in an <asp:UpdatePanel>
and add AsyncPostBackTrigger of TextChanged
event. You can verify, validate and change the string from the server side using that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With