Search code examples
c#jqueryasp.netcontrolsglobalization

Why is the text on asp.net controls is not changed when changing uiCulture


I have user control on aspx page.
The uc has dropdownlist control for selecting one of three languages: Hebrew (default), English or Russian.
I have three resx pages contain the translation of each language.
when the user selects a language, I change the uiCulture of the parent page to selected option:

this.Page.UICulture = language;  

It works.
but... not completely.
I have div defined as follow:

<div class="col col-md-3 col-xs-4"><%= Resources.MyResource.CurrencyText %></div>  

and its content changed as expected.
but I have also dropdownlist defined:

<asp:DropDownList ID="ddlCurrency" CssClass="form-control" runat="server" Height="16px">
  <asp:ListItem Value="1" Text="<%$ Resources:MyResource,shekelOpt %>"></asp:listitem>
  <asp:ListItem Value="2"  Text="<%$ Resources:MyResource,dollarOpt %>"></asp:ListItem>
</asp:DropDownList>  

and it does not changes at all.
I tried to workaround and ti write in $(document).ready function something like:

$("#<%= ddlCurrency.ClientID %> option:nth-child(1)").text("<%= Resources.MyResource.shekelOpt %>");
$("#<%= ddlCurrency.ClientID %> option:nth-child(2)").text("<%= Resources.MyResource.dollarOpt %>");  

it works, but I don't like this solution, It is ugly and not enough built.

can someone help and tell me how to cause the text on asp:dropdownlist (and also on asp:button) to be changed?

screenshot


Solution

  • Add this in ResourceClearing.aspx.vb for testing ru-RU culture. Do not set the culture outside of InitializeCulture:

    protected override void InitializeCulture()
                    {
                        Thread.CurrentThread.CurrentCulture = new CultureInfo("ru-RU");
                        base.InitializeCulture();
                    }
    

    Add this in ResourceClearing.aspx Page

    <asp:DropDownList ID="ddlCurrency" CssClass="form-control" runat="server" Height="16px">
      <asp:ListItem Value="1" Text="<%$ Resources:shekelOpt %>"></asp:listitem>
      <asp:ListItem Value="2"  Text="<%$ Resources:dollarOpt %>"></asp:ListItem>
    </asp:DropDownList> 
    

    If that doesn't work add this markup in ResourceClearing.aspx Page

    <asp:DropDownList ID="ddlCurrency" CssClass="form-control" runat="server" Height="16px" meta:resourcekey="ddlCurrencyResource1" >
                    <asp:ListItem Value="1" Text="Shekal" meta:resourcekey="ListItemResource1"></asp:ListItem>
                    <asp:ListItem Value="2"  Text="Dollar" meta:resourcekey="ListItemResource2"></asp:ListItem>
                </asp:DropDownList>
    

    And add the following entries in all 3 resource files with their values:

    enter image description here