Link to home
Start Free TrialLog in
Avatar of need_code
need_codeFlag for United States of America

asked on

How can I pass the Current UICulture & CurrentCulture to another page as a session variable?

In my application, the users can pick a language. I would like to use the selected culture/language as a session variable so that it can be used on the next page.  Should I use a session variable?  Or is there a better way to do this?
.cs file
    protected override void InitializeCulture()
    {
        string lang = Request["Language1"];
        if (lang != null && lang != "")
        {
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
        }
   
    }

.aspx file

<asp:DropDownList ID="Language1"
                    runat="server" AutoPostBack="True"
            meta:resourcekey="Language1Resource1"
            onselectedindexchanged="Language1_SelectedIndexChanged">
            <asp:ListItem Value="en-US" meta:resourcekey="ListItemResource1">Auto</asp:ListItem>
            <asp:ListItem Value="en-US" meta:resourcekey="ListItemResource2">English (US)</asp:ListItem>
            <asp:ListItem Value="es-mx" meta:resourcekey="ListItemResource3">Spanish (MX)</asp:ListItem>
            </asp:DropDownList>  
Avatar of rajapandian_81
rajapandian_81
Flag of India image

Yes. You can use Session.

To store a value in session use below code.
Session["lang"] = lang;

To get that session value in other page, use below code
string strLang = Session["lang"].ToString();
Avatar of need_code

ASKER

Thanks.  Now how do I use it to set the Culture information?
ASKER CERTIFIED SOLUTION
Avatar of need_code
need_code
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial