Asp.net 在运行时使用资源文件进行本地化

Asp.net 在运行时使用资源文件进行本地化,asp.net,webforms,localization,runtime,globalization,Asp.net,Webforms,Localization,Runtime,Globalization,我有一个具有本地化功能的Web表单。我已经添加了西班牙语作为网络表单的第二语言,它非常有效。但是我发现了一个问题,我只能用一种语言启动webform(英语或西班牙语),但我想在运行时更改它 我想通过在webform中添加以下功能来进一步改进这一点 1) 在运行时通过下拉框选择语言(英语或西班牙语) 2) 将默认语言“英语”显示为“第一”,如果用户希望更改,则应从下拉框中选择 上述两个功能是否可以添加?如果是,请说明如何进行 这是我的网络表单代码: <%

我有一个具有本地化功能的Web表单。我已经添加了西班牙语作为网络表单的第二语言,它非常有效。但是我发现了一个问题,我只能用一种语言启动webform(英语或西班牙语),但我想在运行时更改它

我想通过在webform中添加以下功能来进一步改进这一点

1) 在运行时通过下拉框选择语言(英语或西班牙语)

2) 将默认语言“英语”显示为“第一”,如果用户希望更改,则应从下拉框中选择

上述两个功能是否可以添加?如果是,请说明如何进行

这是我的网络表单代码:

                   <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="About_Company.aspx.cs" Inherits="AutoMobileWebsite.AboutUs" UICulture="es-ES"%>

        <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
   <head runat="server">
    <title>Company</title>
  </head>
  <body>
  <form id="form1" runat="server">

  <div>
        <asp:Label id="lblAboutCM" runat="server" meta:resourcekey="lblAboutCM"><h1>About Company :</h1></asp:Label> 
</div>

    <div>   
    <asp:Label id="lblContent" runat="server" meta:resourcekey="lblContent"> <h3> The company was established in 2014 by the founder Rex Chris. 
        The intention of this website is provide our customers and online virtual car sale which 
        anytype of customer can buy their dream vehicle or sell the existing vehicle
        </h3>
       </asp:Label>
</div>

  </form>

</body>

单位
关于公司:
该公司由创始人雷克斯·克里斯于2014年成立。
本网站的目的是为我们的客户提供在线虚拟汽车销售
任何类型的客户都可以购买他们的梦想车辆或出售现有车辆

如何实现上述功能

感谢您抽出时间

ASPX:

<form id="form1" runat="server">
Language:<br />
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" 
    onselectedindexchanged="DropDownList1_SelectedIndexChanged">
    <asp:ListItem Value="English">English</asp:ListItem>
    <asp:ListItem>Spanish</asp:ListItem>
</asp:DropDownList>
    <div>
    <asp:Label id="eng_lblAboutCM" runat="server" meta:resourcekey="lblAboutCM"><h1>english about :</h1></asp:Label> 
     <asp:Label id="sp_lblAboutCM" runat="server" meta:resourcekey="lblAboutCM"> <h1>spanish about :</h1></asp:Label> 
</div>
<div>   
<asp:Label id="eng_lblContent" runat="server" meta:resourcekey="lblContent"> <h3> english content
    </h3>
</asp:Label>
   <asp:Label id="sp_lblContent" runat="server" meta:resourcekey="lblContent"> <h3> spanish content
    </h3>
   </asp:Label>
   </div>
  </form>
看看这个
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ChangeLanguage();
    }
    private void ChangeLanguage()
    {
        foreach (var item in form1.Controls)
        {
            if (item is Label)
            {
                Label lbl = (Label)item;
                lbl.Visible = false;
                if (lbl.ID.StartsWith("eng") &&
                    DropDownList1.SelectedItem.Text == "English")
                {
                    lbl.Visible = true;
                }
                else if (lbl.ID.StartsWith("sp") &&
                    DropDownList1.SelectedItem.Text == "Spanish")
                {
                    lbl.Visible = true;
                }
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ChangeLanguage();
        }
    }