Link to home
Start Free TrialLog in
Avatar of alexp27
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.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?
ASKER CERTIFIED SOLUTION
Avatar of bedanand
bedanand
Flag of Nepal 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
Avatar of alexp27
alexp27

ASKER

thanks for the answer