alexp27
asked on
Thread.CurrentThread.CurrentCulture in an ajax method
I am trying to build a simple webpage to test globalization in an AJAX event.
what I have is this:
[System.Web.Services.WebMe thod(Enabl eSession=t rue)]
public static void ChangeCulture(string culture)
{
Global.Culture = culture;
try
{
Thread.CurrentThread.Curre ntCulture = new CultureInfo(Global.Culture );
}
catch (Exception)
{
Thread.CurrentThread.Curre ntCulture = new CultureInfo("en-GB");
}
Thread.CurrentThread.Curre ntUICultur e = Thread.CurrentThread.Curre ntCulture;
}
where Global.Culture is defined as:
public static class Global
{
public static string Culture
{
get
{
if (HttpContext.Current.Reque st.Cookies ["Culture" ] == null) return null;
return HttpContext.Current.Reques t.Cookies[ "Culture"] .Value;
}
set
{
if (HttpContext.Current.Respo nse.Cookie s["Culture "] == null)
HttpContext.Current.Respon se.Cookies .Add(new HttpCookie("Culture", value));
else HttpContext.Current.Respon se.Cookies ["Culture" ].Value = value;
}
}
}
now, when I click the button that invokes the method above, the method runs, the cookie is set, the Thread.CurrentThread.Curre ntCulture is also set to the correct value. But the next time another ajax method runs, Thread.CurrentThread.Curre ntCulture is back to the default en-US.
I should mention my ScriptManager tag looks like this:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnableScriptGlobalization= "true" EnableScriptLocalization=" true">
what am I missing?
what I have is this:
[System.Web.Services.WebMe
public static void ChangeCulture(string culture)
{
Global.Culture = culture;
try
{
Thread.CurrentThread.Curre
}
catch (Exception)
{
Thread.CurrentThread.Curre
}
Thread.CurrentThread.Curre
}
where Global.Culture is defined as:
public static class Global
{
public static string Culture
{
get
{
if (HttpContext.Current.Reque
return HttpContext.Current.Reques
}
set
{
if (HttpContext.Current.Respo
HttpContext.Current.Respon
else HttpContext.Current.Respon
}
}
}
now, when I click the button that invokes the method above, the method runs, the cookie is set, the Thread.CurrentThread.Curre
I should mention my ScriptManager tag looks like this:
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" EnableScriptGlobalization=
what am I missing?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER