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.WebMethod(EnableSession=true)]
    public static void ChangeCulture(string culture)
    {

        Global.Culture = culture;
        try
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo(Global.Culture);
        }
        catch (Exception)
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
        }
        Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
    }


where Global.Culture is defined as:

public static class Global
{
    public static string Culture
    {
        get
        {
            if (HttpContext.Current.Request.Cookies["Culture"] == null) return null;
            return HttpContext.Current.Request.Cookies["Culture"].Value;
        }
        set
        {
            if (HttpContext.Current.Response.Cookies["Culture"] == null)
                HttpContext.Current.Response.Cookies.Add(new HttpCookie("Culture", value));
            else HttpContext.Current.Response.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.CurrentCulture is also set to the correct value. But the next time another ajax method runs, Thread.CurrentThread.CurrentCulture 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?
alexp27Asked:
Who is Participating?
 
bedanandCommented:
My understanding is each request creates its own thread. so on the next request it creates next thread.

Try saving culture in the session and set threads culture on each reqeust.


Thanks
0
 
alexp27Author Commented:
thanks for the answer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.