Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Globalization issue on asp.net: it's not updating accentuated words

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();
    }
like image 883
Leandro Gonçalves Avatar asked Nov 11 '22 14:11

Leandro Gonçalves


1 Answers

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

<asp:TemplateField ...>
    <ItemTemplate><%# Eval( "Ocupacao" ) %></ItemTemplate>
</asp:TemplateField>
like image 179
JustAndrei Avatar answered Nov 14 '22 22:11

JustAndrei