title: Localization inside an ascx user control
body: <p>----------------OLD CODE ----------------------------------------------
  I have create a user control, which is a Main Menu, that has to be localized.  So I have created 3 resource files inside the App_LocalResources, and I have a dropdown to change the languages selected.</p>
  
  <p>The Main Menu looks like this :-</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MainMenu.ascx.cs" Inherits="GGX4._2.MainMenu" %&gt;
  &lt;div&gt;
      &lt;asp:DropDownList ID="ddlLangs" runat="server" 
          onselectedindexchanged="ddlLangs_SelectedIndexChanged" AutoPostBack="True" meta:resourcekey="ddlLangsResource1"&gt;
          &lt;asp:ListItem Text="English" Value="en-US" meta:resourcekey="ListItemResource1"&gt;&lt;/asp:ListItem&gt;
          &lt;asp:ListItem Text="German" Value="de-DE" meta:resourcekey="ListItemResource2"&gt;&lt;/asp:ListItem&gt;
          &lt;asp:ListItem Text="Spanish" Value="es-ES" meta:resourcekey="ListItemResource3"&gt;&lt;/asp:ListItem&gt;
      &lt;/asp:DropDownList&gt;
  &lt;/div&gt;
  &lt;div&gt;
      &lt;table&gt;
        &lt;tr&gt;
          &lt;td width="100%" nowrap height="16"&gt;
          &lt;img border="0" src="Images/GREENSQUARE.gif" width="16" height="16"&gt;&lt;b&gt;&lt;font size="2" face="Arial"&gt;
              &lt;asp:HyperLink ID="hypIntroduction" runat="server" NavigateUrl="Overview.htm" 
                  meta:resourcekey="hypIntroductionResource1" &gt;[hypIntroduction]&lt;/asp:HyperLink&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td width="100%" nowrap height="16"&gt;
          &lt;img border="0" src="Images/GREENSQUARE.gif" width="16" height="16"&gt;&lt;b&gt;&lt;font size="2" face="Arial"&gt;
              &lt;asp:HyperLink ID="hypGlobalGradingMethodology" runat="server" NavigateUrl="GGMethodology.htm" 
                  meta:resourcekey="hypGlobalGradingMethodologyResource1" &gt;[hypGlobalGradingMethodology]&lt;/asp:HyperLink&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td width="100%" nowrap height="16"&gt;
          &lt;img border="0" src="Images/Redsquare.gif" width="16" height="16"&gt;&lt;b&gt;&lt;font size="2" face="Arial"&gt;
              &lt;asp:HyperLink ID="hypDeterminingBusiness" runat="server" 
                  NavigateUrl="ScopematrixGeneral.htm" 
                  meta:resourcekey="hypDeterminingBusinessResource1"&gt;[hypDeterminingBusiness]&lt;/asp:HyperLink&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;td width="100%" nowrap height="16"&gt;&lt;font size="2" face="Arial"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
          &lt;img border="0" src="Images/BLUEBULLET.gif" width="16" height="16"&gt;
              &lt;asp:HyperLink ID="hypMethodology" runat="server" 
                  NavigateUrl="methodology.htm" 
                  meta:resourcekey="hypMethodologyResource1"&gt;[hypMethodology]&lt;/asp:HyperLink&gt;
            &lt;/font&gt;
          &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and in the code behind I have the following :-</p>
  
  <pre><code>        string defaultLanguage = Thread.CurrentThread.CurrentUICulture.ToString();
  
  
      protected void Page_Load(object sender, EventArgs e)
      {
          this.InitializeCulture();
      }
  
      protected void InitializeCulture()
      {
          if (String.IsNullOrEmpty(CurrentCulture))
          {
              CurrentCulture = defaultLanguage;
          }            
  
          if (!String.IsNullOrEmpty(CurrentCulture))
          {
              try
              {
                  Thread.CurrentThread.CurrentCulture = new CultureInfo(CurrentCulture);
                  Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
              }
              catch
              {
                  throw;
              }
          }
      }
  
      public String CurrentCulture
      {
          get
          {
              if (null != Session["PreferedCulture"])
                  return Session["PreferedCulture"].ToString();
              else
                  return "en-US";
          }
          set
          {
              Session["PreferedCulture"] = value;
          }
      }
  
  
      protected void ddlLangs_SelectedIndexChanged(object sender, EventArgs e)
      {
          Session["PreferedCulture"] = ddlLangs.SelectedValue;
          InitializeCulture();
      }
  </code></pre>
  
  <p>However when I do the change in the dropdownlist, the Culture reamins the same.  Normally when applied to a System.Web.UI.Page, I would override the InitializeCulture(), however I cannot find a way to do it in the ascx.</p>
  
  <p>How can I achieve that?</p>
  
  <p>Thanks for your help and time</p>
  
  <p>-------------NEW CODE-----------------------------------------------</p>
  
  <p>I have decided to make things simpler, and I have managed to achieve what I want, however with a page refresh which I do not like at all and wish to make without.</p>
  
  <p>So basically I have created a simple example that is working now :-</p>
  
  <p>The Site.Master just has the drop-down as the extra code :-</p>
  
  <pre><code>            &lt;div&gt;
              &lt;asp:DropDownList ID="ddlLangs" runat="server" onselectedindexchanged="ddlLangs_SelectedIndexChanged" AutoPostBack="True" 
                      meta:resourcekey="ddlLangsResource1"&gt;
                  &lt;asp:ListItem Text="English" Value="en-US" 
                      meta:resourcekey="ListItemResource1" &gt;&lt;/asp:ListItem&gt;
                  &lt;asp:ListItem Text="German" Value="fr-FR" meta:resourcekey="ListItemResource2" &gt;&lt;/asp:ListItem&gt;
                  &lt;asp:ListItem Text="Spanish" Value="it-IT" 
                      meta:resourcekey="ListItemResource3" &gt;&lt;/asp:ListItem&gt;
              &lt;/asp:DropDownList&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>and the code behind looks like this:-</p>
  
  <pre><code>       protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              if (Session["PreferredCulture"]!= null)
                  ddlLangs.SelectedValue = Session["PreferredCulture"].ToString();
  
          }
      }
  
      protected void ddlLangs_SelectedIndexChanged(object sender, EventArgs e)
      {
          Session["PreferredCulture"] = ddlLangs.SelectedValue;
          Server.Transfer(Request.Path);
      }
  </code></pre>
  
  <p>The Default.aspx has the MainMenu UC, and a sample label, however it inheris from the BasePage :-</p>
  
  <pre><code>&lt;asp:Content ID="MenuContent" runat="server" ContentPlaceHolderID="MainMenuContent"&gt;
  &lt;uc:MainMenu runat="server" ID="ucMainMenu" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>
      <h2>
          Welcome to ASP.NET!
      </h2>
      </p>
  
  <pre><code>&lt;/asp:Content&gt;
  </code></pre>
  
  <p>And the BasePage has the code to Initialize the Culture</p>
  
  <p>I wish to get rid of the Server.Transfer(Request.Path), and avoid refreshing the page, however I have not found out a method yet.</p>
  
  <p>Any help/ideas will be very much appreciated!</p>
  
  <p>Thanks</p>