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>  
need_codeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rajapandian_81Commented:
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();
0
need_codeAuthor Commented:
Thanks.  Now how do I use it to set the Culture information?
0
need_codeAuthor Commented:
This is what worked for me.

protected string SessionCulture
    {
        get
        {
            return Session["lang"] as string;
        }
        set
        {
            Session["lang"] = value;
        }
    }

    protected string SelectedCulture
    {
        get
        {
            return Request.Form["Language1"];
        }
    }

    protected override void InitializeCulture()
    {

        string lang = SelectedCulture ?? SessionCulture;

        if (lang != null)
        {
            UICulture = lang;
            Culture = lang;
            SessionCulture = lang;
        }
        base.InitializeCulture();
         
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string lang = SelectedCulture ?? SessionCulture;
            if (lang != null)
            {
                for (int i = 0; i < Language1.Items.Count; i++)
                {
                    ListItem item = Language1.Items[i];
                    if (item.Value.Equals(lang))
                    {
                        Language1.SelectedIndex = i;
                        break;
                    }
                }
            }
        }

On the receiving page I used:

protected override void InitializeCulture()
    {
        if (Session["lang"] != null)
        {
            string lang = Session["lang"] as string;
            UICulture = lang;
            Culture = lang;
        }
        base.InitializeCulture();
    }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.