1.首先建立资源文件strings.resx,再建立strings.en-us.resx,strings.zh-cn.resx,strings.zh_hk.resx.必须要有strings.resx,这个文件可以没有任何内容.但必须有.不然在下面的default.aspx.cs中,visual studio会自动提示把这些资源文件放在App_GlobalResources目录下.
2.应用程序根目录下建立有时候叫做 ASP.NET 应用程序文件Global.asax.增加以下代码
 void Application_BeginRequest(object sender, EventArgs e)
    void Application_BeginRequest(object sender, EventArgs e)
 {
    {
 try
        try
 {
        {
 if (Request.Cookies["CultureResource"] != null)
            if (Request.Cookies["CultureResource"] != null)
 System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(Request.Cookies["CultureResource"].Value);
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(Request.Cookies["CultureResource"].Value);
 else
            else
 System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(ConfigurationSettings.AppSettings["DefaultCulture"].ToString());
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(ConfigurationSettings.AppSettings["DefaultCulture"].ToString());
 System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
 }
        }
 catch (Exception)
        catch (Exception)
 {
        {
 System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(ConfigurationSettings.AppSettings["DefaultCulture"].ToString());
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(ConfigurationSettings.AppSettings["DefaultCulture"].ToString());
 }
        }
 
         
 }
    }

每次访问页面时,程序都在运行这段代码一次.不知道有谁能有更好的方法.我觉得这样不是很好.麻烦提示哦!
3.以下是页面的代码
aspx
 <TABLE id="Table1" align="center" cellSpacing="0" cellPadding="0" width="100%" border="0">
 <TABLE id="Table1" align="center" cellSpacing="0" cellPadding="0" width="100%" border="0">
 <colgroup>
                            <colgroup>
 <col width="50%">
                                <col width="50%">
 </col>
                                </col>
 <col width="50%">
                                <col width="50%">
 </col>
                                </col>
 </colgroup>
                            </colgroup>
 <TR>
                            <TR>
 <TD align="right"><%=Resource("language") %>:</TD>
                                <TD align="right"><%=Resource("language") %>:</TD>
 <TD>
                                <TD>
 <asp:Button id="Button1" runat="server" Text="中文" OnClick="Button1_Click"></asp:Button>
                                    <asp:Button id="Button1" runat="server" Text="中文" OnClick="Button1_Click"></asp:Button>
 <asp:Button id="Button2" runat="server" Text="英文" OnClick="Button2_Click"></asp:Button>
                                    <asp:Button id="Button2" runat="server" Text="英文" OnClick="Button2_Click"></asp:Button>
 <asp:Button id="Button3" runat="server" Text="繁体中文" OnClick="Button3_Click"></asp:Button>
                                    <asp:Button id="Button3" runat="server" Text="繁体中文" OnClick="Button3_Click"></asp:Button>
 </TD>
                                </TD>
 </TR>
                            </TR>
 <TR>
                            <TR>
 <TD align="right">
                                <TD align="right">
 <asp:Label id="Label1" runat="server">Label</asp:Label>:</TD>
                                    <asp:Label id="Label1" runat="server">Label</asp:Label>:</TD>
 <TD>
                                <TD>
 <asp:TextBox id="txtLoginName" runat="server" Width="100%"></asp:TextBox></TD>
                                    <asp:TextBox id="txtLoginName" runat="server" Width="100%"></asp:TextBox></TD>
 </TR>
                            </TR>
 <TR>
                            <TR>
 <TD align="right">
                                <TD align="right">
 <asp:Label id="Label2" runat="server">Label</asp:Label>:</TD>
                                    <asp:Label id="Label2" runat="server">Label</asp:Label>:</TD>
 <TD>
                                <TD>
 <asp:TextBox id="txtPassword" runat="server" Width="100%"></asp:TextBox></TD>
                                    <asp:TextBox id="txtPassword" runat="server" Width="100%"></asp:TextBox></TD>
 </TR>
                            </TR>
 </TABLE>
                        </TABLE>
aspx.cs
 using System;
using System;
 using System.Data;
using System.Data;
 using System.Configuration;
using System.Configuration;
 using System.Web;
using System.Web;
 using System.Web.Security;
using System.Web.Security;
 using System.Web.UI;
using System.Web.UI;
 using System.Web.UI.WebControls;
using System.Web.UI.WebControls;
 using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls.WebParts;
 using System.Web.UI.HtmlControls;
using System.Web.UI.HtmlControls;
 using System.Resources;
using System.Resources;
 using System.Globalization;
using System.Globalization;
 using System.Reflection;
using System.Reflection;
 using Microsoft.VisualBasic;
using Microsoft.VisualBasic;

 public partial class _Default : System.Web.UI.Page
public partial class _Default : System.Web.UI.Page 
 {
{
 protected void Page_Load(object sender, EventArgs e)
    protected void Page_Load(object sender, EventArgs e)
 {
    {
 Label1.Text = Resource("LoginName");
        Label1.Text = Resource("LoginName");
 Label2.Text = Resource("Password");
        Label2.Text = Resource("Password");

 }
    }
 
      

 Resource
    Resource


 protected void Button1_Click(object sender, EventArgs e)
    protected void Button1_Click(object sender, EventArgs e)
 {
    {
 this.UpdateCultureCookie(ConfigurationSettings.AppSettings["CNCulture"].ToString());
        this.UpdateCultureCookie(ConfigurationSettings.AppSettings["CNCulture"].ToString());
 System.Web.UI.Page currentPage = (System.Web.UI.Page)this;
        System.Web.UI.Page currentPage = (System.Web.UI.Page)this;
 Response.Redirect(currentPage.Request.Url.ToString());
        Response.Redirect(currentPage.Request.Url.ToString());
 }
    }
 protected void Button2_Click(object sender, EventArgs e)
    protected void Button2_Click(object sender, EventArgs e)
 {
    {
 this.UpdateCultureCookie(ConfigurationSettings.AppSettings["ENCulture"].ToString());
        this.UpdateCultureCookie(ConfigurationSettings.AppSettings["ENCulture"].ToString());
 System.Web.UI.Page currentPage = (System.Web.UI.Page)this;
        System.Web.UI.Page currentPage = (System.Web.UI.Page)this;
 Response.Redirect(currentPage.Request.Url.ToString());
        Response.Redirect(currentPage.Request.Url.ToString());

 }
    }
 }strings.zh-cn.resx
}strings.zh-cn.resx
在视图下增加三个字段
同样strings.zh-hk.resx
string.en-us.resx
   #region Resource
    public string Resource(string key)
    {
        string resourceValue = null;
        CultureInfo ci = CultureInfo.CurrentCulture;
        ResourceManager rm = Resources.strings.ResourceManager;
        resourceValue = rm.GetString(key, ci);
        return resourceValue;
    }
    #endregion
2.应用程序根目录下建立有时候叫做 ASP.NET 应用程序文件Global.asax.增加以下代码
 void Application_BeginRequest(object sender, EventArgs e)
    void Application_BeginRequest(object sender, EventArgs e) {
    { try
        try {
        { if (Request.Cookies["CultureResource"] != null)
            if (Request.Cookies["CultureResource"] != null) System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(Request.Cookies["CultureResource"].Value);
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(Request.Cookies["CultureResource"].Value); else
            else System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(ConfigurationSettings.AppSettings["DefaultCulture"].ToString());
                System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(ConfigurationSettings.AppSettings["DefaultCulture"].ToString()); System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
            System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture; }
        } catch (Exception)
        catch (Exception) {
        { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(ConfigurationSettings.AppSettings["DefaultCulture"].ToString());
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(ConfigurationSettings.AppSettings["DefaultCulture"].ToString()); }
        } 
          }
    }
每次访问页面时,程序都在运行这段代码一次.不知道有谁能有更好的方法.我觉得这样不是很好.麻烦提示哦!
3.以下是页面的代码
aspx
 <TABLE id="Table1" align="center" cellSpacing="0" cellPadding="0" width="100%" border="0">
 <TABLE id="Table1" align="center" cellSpacing="0" cellPadding="0" width="100%" border="0"> <colgroup>
                            <colgroup> <col width="50%">
                                <col width="50%"> </col>
                                </col> <col width="50%">
                                <col width="50%"> </col>
                                </col> </colgroup>
                            </colgroup> <TR>
                            <TR> <TD align="right"><%=Resource("language") %>:</TD>
                                <TD align="right"><%=Resource("language") %>:</TD> <TD>
                                <TD> <asp:Button id="Button1" runat="server" Text="中文" OnClick="Button1_Click"></asp:Button>
                                    <asp:Button id="Button1" runat="server" Text="中文" OnClick="Button1_Click"></asp:Button> <asp:Button id="Button2" runat="server" Text="英文" OnClick="Button2_Click"></asp:Button>
                                    <asp:Button id="Button2" runat="server" Text="英文" OnClick="Button2_Click"></asp:Button> <asp:Button id="Button3" runat="server" Text="繁体中文" OnClick="Button3_Click"></asp:Button>
                                    <asp:Button id="Button3" runat="server" Text="繁体中文" OnClick="Button3_Click"></asp:Button> </TD>
                                </TD> </TR>
                            </TR> <TR>
                            <TR> <TD align="right">
                                <TD align="right"> <asp:Label id="Label1" runat="server">Label</asp:Label>:</TD>
                                    <asp:Label id="Label1" runat="server">Label</asp:Label>:</TD> <TD>
                                <TD> <asp:TextBox id="txtLoginName" runat="server" Width="100%"></asp:TextBox></TD>
                                    <asp:TextBox id="txtLoginName" runat="server" Width="100%"></asp:TextBox></TD> </TR>
                            </TR> <TR>
                            <TR> <TD align="right">
                                <TD align="right"> <asp:Label id="Label2" runat="server">Label</asp:Label>:</TD>
                                    <asp:Label id="Label2" runat="server">Label</asp:Label>:</TD> <TD>
                                <TD> <asp:TextBox id="txtPassword" runat="server" Width="100%"></asp:TextBox></TD>
                                    <asp:TextBox id="txtPassword" runat="server" Width="100%"></asp:TextBox></TD> </TR>
                            </TR> </TABLE>
                        </TABLE>aspx.cs
 using System;
using System; using System.Data;
using System.Data; using System.Configuration;
using System.Configuration; using System.Web;
using System.Web; using System.Web.Security;
using System.Web.Security; using System.Web.UI;
using System.Web.UI; using System.Web.UI.WebControls;
using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;
using System.Web.UI.HtmlControls; using System.Resources;
using System.Resources; using System.Globalization;
using System.Globalization; using System.Reflection;
using System.Reflection; using Microsoft.VisualBasic;
using Microsoft.VisualBasic;
 public partial class _Default : System.Web.UI.Page
public partial class _Default : System.Web.UI.Page  {
{ protected void Page_Load(object sender, EventArgs e)
    protected void Page_Load(object sender, EventArgs e) {
    { Label1.Text = Resource("LoginName");
        Label1.Text = Resource("LoginName"); Label2.Text = Resource("Password");
        Label2.Text = Resource("Password");
 }
    } 
      
 Resource
    Resource

 protected void Button1_Click(object sender, EventArgs e)
    protected void Button1_Click(object sender, EventArgs e) {
    { this.UpdateCultureCookie(ConfigurationSettings.AppSettings["CNCulture"].ToString());
        this.UpdateCultureCookie(ConfigurationSettings.AppSettings["CNCulture"].ToString()); System.Web.UI.Page currentPage = (System.Web.UI.Page)this;
        System.Web.UI.Page currentPage = (System.Web.UI.Page)this; Response.Redirect(currentPage.Request.Url.ToString());
        Response.Redirect(currentPage.Request.Url.ToString()); }
    } protected void Button2_Click(object sender, EventArgs e)
    protected void Button2_Click(object sender, EventArgs e) {
    { this.UpdateCultureCookie(ConfigurationSettings.AppSettings["ENCulture"].ToString());
        this.UpdateCultureCookie(ConfigurationSettings.AppSettings["ENCulture"].ToString()); System.Web.UI.Page currentPage = (System.Web.UI.Page)this;
        System.Web.UI.Page currentPage = (System.Web.UI.Page)this; Response.Redirect(currentPage.Request.Url.ToString());
        Response.Redirect(currentPage.Request.Url.ToString());
 }
    } }
}在视图下增加三个字段
| language | 请选择语言 | 
| LoginName | 用户名 | 
| Password | 密码 | 
同样strings.zh-hk.resx
| language | 請選擇語言 | 
| LoginName | 用戶名 | 
| Password | 密碼 | 
string.en-us.resx
| language | Please Select Language | 
| LoginName | Username | 
| Password | Password | 
 
                    
                     
                    
                 
                    
                 
 
    
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号