Question

I've created an website available in three languages: english, portuguese and spanish.

It's everything working fine except for one thing: it was not updating a BoundField when an accentuated word is loaded into it.

Below is the field which doesn't update in the gridview at MEMGridView.ascx:

<asp:BoundField  DataField="Ocupacao" HeaderText="Ocupação" SortExpression="Ocupação" meta:resourcekey="BoundFieldResource9">
     <ItemStyle HorizontalAlign="Center" />
</asp:BoundField>

At App_LocalResources are three files with this values:

  1. MEMGridView.ascx.resx (english is default) - BoundFieldResource9.HeaderText - "Fill Rate"
  2. MEMGridView.ascx.pt-BR.resx - BoundFieldResource9.HeaderText - "Ocupação"
  3. MEMGridView.ascx.es.resx - BoundFieldResource9.HeaderText - "Ocupación"

When the page loads for the first time it exhibits "Fill Rate". Then I change the language to spanish and it exhibits "Ocupación". If I return to load the page in english it updates all fields, except for the accentuated ones. So it continues to show "Ocupación" instead of "Fill Rate".

I have no clues of what can be happening.

-- Update - Additional Info --

MEMGridView is a UserControl inside of DashBoard.aspx. Everytime someone changes the language value in ddlLanguage (dropdownlist) or clicks on Update button a postback is generated.

This is the MEMGridView event suposed to update the fields (actually, it updates all fields except the accentuated ones).

public partial class MEMGridView : UserControl
{
    ...

    protected override void FrameworkInitialize()
    {
        if (!string.IsNullOrEmpty(Request["ddlLanguage"]))
        {
            string str = Request["ddlLanguage"];

            //Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(str);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(str);
        }
        else
        {
            string preferredLanguage;

            if (Request.QueryString["Language"] != null)
                preferredLanguage = Request.QueryString["Language"];
            else
                preferredLanguage = Request.UserLanguages[0];

            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(preferredLanguage);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(preferredLanguage);
        }

        base.FrameworkInitialize();
    }
Was it helpful?

Solution

Encountered same problem. Fixed by replacing the BoundField with TemplateField, just like that:

<asp:TemplateField ...>
    <ItemTemplate><%# Eval( "Ocupacao" ) %></ItemTemplate>
</asp:TemplateField>

OTHER TIPS

Would you be able to override the InitializeCulture from the Page (not MasterPage)?

http://msdn.microsoft.com/en-us/library/system.web.ui.page.initializeculture(v=vs.110).aspx

Also, when you say you "return to load the page in english", how did you do that? Is that via browser navigation or Server.Transfer? If it's the latter, did you use:

Server.Transfer(Request.Url.PathAndQuery, false);

http://www.c-sharpcorner.com/UploadFile/4d9083/what-is-globalization-and-localization-in-Asp-Net/

this link will help you


Text="<%$Resources:Resource,AccCode%>"

"<%$Resources:Your Main Resource file Name, Add Name Of Resource field which you want to display %>"

< asp:Label ID="lblresdisplay" Font-Size="Large" runat="server" Text="<%$Resources:Resource,AccCode%>">

< asp:Label ID="Label1" Font-Size="Large" runat="server" Text="<%$Resources:Resource,AccCode%>">


--protected override void InitializeCulture()

{

    base.InitializeCulture();

    System.Threading.Thread.CurrentThread.CurrentCulture = new   System.Globalization.CultureInfo(Session["Culture"].ToString());

    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(Session["Culture"].ToString());



}

}

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top