如何在asp.NETC中应用Web用户控件的全球化#

如何在asp.NETC中应用Web用户控件的全球化#,asp.net,c#-4.0,globalization,webusercontrol,Asp.net,C# 4.0,Globalization,Webusercontrol,我已经在默认页面上应用了全球化,但它没有应用于Web用户控件。 我已经创建了Header.ascx并放置了两个linkButton,一个用于英语,另一个用于西班牙语。 我正在标题上使用代码。ascx表单代码如下 这是英语的代码 protected void lbtnEng_Click(object sender, EventArgs e) { HttpCookie cookie = new HttpCookie("CultureInfo"); cook

我已经在默认页面上应用了全球化,但它没有应用于Web用户控件。 我已经创建了Header.ascx并放置了两个linkButton,一个用于英语,另一个用于西班牙语。 我正在标题上使用代码。ascx表单代码如下

这是英语的代码

 protected void lbtnEng_Click(object sender, EventArgs e)
    {

        HttpCookie cookie = new HttpCookie("CultureInfo");
        cookie.Value = "en";
        Response.Cookies.Add(cookie);
        Thread.CurrentThread.CurrentCulture = new CultureInfo("en");
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en");
        Server.Transfer(Request.Path);

    }
此代码用于西班牙语

protected void lbtnSpan_Click(object sender, EventArgs e)
{

    HttpCookie cookie = new HttpCookie("CultureInfo");
    cookie.Value = "es-mx";
    Response.Cookies.Add(cookie);
   Thread.CurrentThread.CurrentCulture =  new CultureInfo("es-mx");
    Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-mx");
    Server.Transfer(Request.Path);
  }
此代码更改默认页面标签文本上的语言,但不更改web用户控件标签上的语言 在默认页上声明控件

<asp:Label ID="lbl_test" runat="server" Text="<%$ Resources:Resource, Test %>"></asp:Label>

和web控件

<asp:Label ID="lbl_test" runat="server" Text="<%$ Resources:Resource, Test %>"></asp:Label>

一次只能设置一种语言。为了完成任务,请使用静态字符串或获取一个由键值对组成的资源文件。这是提交密钥的一个示例

ResourceFileForStaticStrings.resx

Key                   Value
submitEnglish         Submit
submitSpanish         Presentar
将其存储在会话或cookie中:尝试以下方法

System.Threading.Thread.CurrentThread.CurrentUICulture = New System.Globalization.CultureInfo(Session("es").ToString)  
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(Session("es").ToString)

我已经创建了两个资源文件,一个是英文版的resource.resx,另一个是西班牙文版的resource.es-mx.resx,我知道您已经创建了两个资源文件。但问题是你不能同时设置两种语言。以便在一个页面中显示两种以上的语言。因此,创建单独的资源文件,正如我上面解释的。当我们单击链接按钮时,我没有得到设置为一种语言的设置,并且还创建了两个单独的文件,一个是resource.resx,一个是resource.es-mx,另一个是resource.es-mx。我是对的吗?不,我正在创建两个链接按钮,一个是英文,第二个是西班牙文,当用户点击西班牙文,然后网站翻译成西班牙文,就像我上面提到的,我创建了两个资源文件