need_code
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.Curre ntUICultur e = new CultureInfo(lang);
Thread.CurrentThread.Curre ntCulture = CultureInfo.CreateSpecific Culture(la ng);
}
}
.aspx file
<asp:DropDownList ID="Language1"
runat="server" AutoPostBack="True"
meta:resourcekey="Language 1Resource1 "
onselectedindexchanged="La nguage1_Se lectedInde xChanged">
<asp:ListItem Value="en-US" meta:resourcekey="ListItem Resource1" >Auto</asp :ListItem>
<asp:ListItem Value="en-US" meta:resourcekey="ListItem Resource2" >English (US)</asp:ListItem>
<asp:ListItem Value="es-mx" meta:resourcekey="ListItem Resource3" >Spanish (MX)</asp:ListItem>
</asp:DropDownList>
.cs file
protected override void InitializeCulture()
{
string lang = Request["Language1"];
if (lang != null && lang != "")
{
Thread.CurrentThread.Curre
Thread.CurrentThread.Curre
}
}
.aspx file
<asp:DropDownList ID="Language1"
runat="server" AutoPostBack="True"
meta:resourcekey="Language
onselectedindexchanged="La
<asp:ListItem Value="en-US" meta:resourcekey="ListItem
<asp:ListItem Value="en-US" meta:resourcekey="ListItem
<asp:ListItem Value="es-mx" meta:resourcekey="ListItem
</asp:DropDownList>
ASKER
Thanks. Now how do I use it to set the Culture information?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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()