locked
Changing Culture for all pages RRS feed

  • Question

  • User-1697551410 posted

    I have viewed the following tutorial http://asp.net/learn/videos/view.aspx?tabid=63&id=40 which shows how to use change the language by usuing the following code

    protected override void InitializeCulture()

    {

    String lang = "en";

    if (langDropDownList != null)

    {

    lang = langDropDownList.SelectedValue;

    }

    Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);

    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);

    }

     I am a novice to asp. I wanted to know how I can change the culture for all subsequent pages. So the user will come in and select either english and french from the login page and all subsequent pages should be in that language. The user should be able to toggle the language back and forth from the login page. Some immediate assistance is required.

    THANKS !!!

    Friday, March 16, 2007 10:27 AM

Answers

  • User-1674285099 posted

    1. Create a new base page class inheriting from System.Web.UI.Page

    2. Imlement following on your new class

    protected override void InitializeCulture()
    
    {
    String lang; if (Session["SelectedCulture"] != null) lang= Session["SelectedCulture"].ToString(); else
    lang ="en";
    Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
    Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
    }
    3. All your aspx pages must be derived from this newly implemented base page class 3. On your login page create a new procedure that sets Session["SelectedCulture"] based on the input received from the user such as following;
    protected bool SetLanguage(String newCulture)
    {
    if ( !ValidLanguage(newCulture)) -- there is no builtin ValidLanugage method, you must implement it to check the user input
    return false;
    	Session["SelectedCulture"]=newCulture;
    return true;
    }

    4. Let user select language pref. from a drop down list and after selection execute the method imlemented in step 3
     
    
     
     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 16, 2007 11:19 AM