locked
Localization Thread culture issue RRS feed

  • Question

  • User-104298894 posted

    Hi ,

     I am working  on localizatin in asp.net 2.0, We r working on multi language web site , so user can toggle between english and french thread and ui cultures.

    Now the issue is , user can always enter data in english mode only ( means 10.25, 30.55, 66.22) , After all the calculations happend i want to display all the page ui controls in French mode with commas ( 10,25, 30,55). Is there any way to resolve this issue . If i am in french mode if user enterd dot(.) 10.25 like that , page throwing error.

     

    any suggestions plzzzzzzzzz

    Thursday, April 26, 2007 2:46 AM

Answers

  • User487807879 posted

    Maybe this will help you (Label is there just for demonstration purposes, only important part is InitializeCulture):

    Default.aspx:
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                <asp:ListItem Value="en-US"></asp:ListItem>
                <asp:ListItem Value="fr-FR"></asp:ListItem>
    </asp:DropDownList>
    <br />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    Default.aspx.cs:
    protected void Page_Load(object sender, EventArgs e)
        {
            double cur = 10.00;
            Label1.Text = cur.ToString("c");
        }
    protected override void InitializeCulture()
        {
            if (Request.Form["DropDownList1"] != null)
            {
                Culture = Request.Form["DropDownList1"];
            }
            base.InitializeCulture();
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 26, 2007 11:38 AM

All replies

  • User445179017 posted

    Are you using the French keyboard layout to enter the data when you are in French mode? Also is the exception its throwing?

    Thanks

    Thursday, April 26, 2007 4:08 AM
  • User487807879 posted

    You can replace comma with dot (or backwards) right after user enter number with this approach:

    TextBox1.Text.Replace(',', '.')

    Thursday, April 26, 2007 4:16 AM
  • User-104298894 posted
    Thanks
    Thursday, April 26, 2007 4:37 AM
  • User-104298894 posted

    but i am trying to do some thing generic

    Thursday, April 26, 2007 4:37 AM
  • User-104298894 posted

    hi kipo,

      that works fine for textbox control , what is abt all the remaining controls .

      I am talking not only abt dot or comma , the user will must and should enter the data in "en-US" mode only , all the calculations will happen in english and finally at the time of rendering i want to display the page in french. Is there any way to do like this.

    Thursday, April 26, 2007 4:45 AM
  • User487807879 posted

    You can do the same logic for all the other contorols, too. For example if you are doing output in Label you can do this:

    double dec = 10.04;
    Label1.Text = dec.ToString().Replace('.',',');

    Thursday, April 26, 2007 5:30 AM
  • User487807879 posted

    You can try with this approach too:

    using System.Globalization;

    CultureInfo info = new CultureInfo("fr-FR");
    double dec = 10.04;
    Label1.Text = dec.ToString("c", info);

    Thursday, April 26, 2007 5:39 AM
  • User-104298894 posted

    My project contains more than 100 pages in that , Today Problem with only one Culture french ,

    Tomorrow i want to toggle 3 or 4 langues , this code will breaks,

    is there any way is there to set in global.asax  file

    Thursday, April 26, 2007 10:06 AM
  • User487807879 posted

    Maybe this will help you (Label is there just for demonstration purposes, only important part is InitializeCulture):

    Default.aspx:
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                <asp:ListItem Value="en-US"></asp:ListItem>
                <asp:ListItem Value="fr-FR"></asp:ListItem>
    </asp:DropDownList>
    <br />
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

    Default.aspx.cs:
    protected void Page_Load(object sender, EventArgs e)
        {
            double cur = 10.00;
            Label1.Text = cur.ToString("c");
        }
    protected override void InitializeCulture()
        {
            if (Request.Form["DropDownList1"] != null)
            {
                Culture = Request.Form["DropDownList1"];
            }
            base.InitializeCulture();
        }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 26, 2007 11:38 AM