views:

55

answers:

1

I have an asp:literal:

<asp:Literal id="language" OnClick="changeLangauge" Text="<%$ Resources:Translate, switchLanguage %>" runat="server"/>

When it is clicked it switches the language:

public void ChangeLanguage(Object sender, EventArgs e)
{
  string lang = langauge.Attribues["class"];
  language.Attributes.Remove("class");
  if (lang.Equals("fr-CA"))
  {
    language.Attributes.Add("class", "en-US");
    Session["lang"] = "en-US";
  }
  else
  {
    language.Attributes.Add("class", "fr-CA");
    Session["lang"] = "fr-CA";
  }
}

I have overrided InitializeCulture, to set the culture based on Session["lang"]. The problem is InitializeCulture gets called before ChangeLanguage. How do I get around this problem?

I have tried to get the class value from asp:Literal control from inside InitializeCulture like this:

public void InitializeCulture(..)
{
    ...
    String selectedLanguage = Request.Form["language"]
    ...
}

but it always returns null.

+2  A: 

My suggestion to get around this is to use AJAX. Asynchronisly call your ChangeLanguage function when the language literal gets clicked.

icemanind
This works. Thanks!
Arizona1911