动态呈现的用户控件的本地化

Localization of dynamic rendered user control

我正在使用以下代码从 JavaScript

动态加载页面
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetSimpleControl(string usercontrolName)
{
    Page page = new Page();
    UserControl ctl = (UserControl)page.LoadControl(usercontrolName);

    page.Controls.Add(ctl);
    StringWriter writer = new StringWriter();
    HttpContext.Current.Server.Execute(page, writer, false);
    return writer.ToString();
}

我的问题是,它没有本地化,但始终使用默认语言。在我正在加载的用户控件中,我尝试调用 InitializeCulture 并设置区域性:

System.Threading.Thread.CurrentThread.CurrentUICulture = cultureInfo

我该如何完成?

通过设置页面的 UICulture 和文化让它工作。 GetSimpleControl 现在看起来像这样

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetSimpleControl(string usercontrolName)
{
    Page page = new Page();
    page.Culture = "en";
    page.UICulture = "en";
    UserControl ctl = (UserControl)page.LoadControl(usercontrolName);

    page.Controls.Add(ctl);
    StringWriter writer = new StringWriter();
    HttpContext.Current.Server.Execute(page, writer, false);
    return writer.ToString();

}