[原创]ASP.NET多语系(1)---前端页面多语系设置

最近在项目中需要使用包括中文简体、中文繁体、英文等多语系。所以留此作为记录。

【1】首先是关于浏览器的语言设置问题。

如果在项目中使用了多语系资源,但是没有后台控制语言设置,页面设置了

那么浏览器会默认显示浏览器语言中的第一个语系(当然,如果项目中没有浏览器设置的语系,则显示项目中设置的默认语系)。

【2】项目中多语系设置

页面初始代码

View Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication.WebForm1" 
Culture="auto" meta:resourcekey="PageResource1" UICulture="auto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>未命名頁面</title>
</head>
<body style="width:100%; height:100%; background-image:url('img/bg.bmp'); background-repeat:repeat; margin:0; padding:0;">
    <form id="form1" runat="server">
    <div style=" text-align:center; ">
    
    <asp:Button ID="btnSearch" runat="server" Text="查询" />
    <br />
    <asp:Localize ID="Localize1" runat="server" Text="单独的字体"></asp:Localize>
    <br />
    <asp:DropDownList ID="ddlType" runat="server">
        <asp:ListItem Text="请选择" Value="0"></asp:ListItem>
        <asp:ListItem Text="中文简体" Value="1"></asp:ListItem>
        <asp:ListItem Text="中文繁体" Value="2"></asp:ListItem>
    </asp:DropDownList>
    </div>
    </form>
</body>
</html>

   然后在aspx设计页面 ,使用菜单栏的【工具 】选项

然后系统自动产生

页面代码变为

View Code
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication.WebForm1" 
Culture="auto" meta:resourcekey="PageResource1" UICulture="auto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>未命名頁面</title>
</head>
<body style="width:100%; height:100%; background-image:url('img/bg.bmp'); background-repeat:repeat; margin:0; padding:0;">
    <form id="form1" runat="server">
    <div style=" text-align:center; ">
    
    <asp:Button ID="btnSearch" runat="server" Text="查询" meta:resourcekey="btnSearchResource1" />
    <br />
    <asp:Localize ID="Localize1" runat="server" Text="单独的字体" meta:resourcekey="Localize1Resource1"></asp:Localize>
    <br />
    <asp:DropDownList ID="ddlType" runat="server" meta:resourcekey="ddlTypeResource1">
        <asp:ListItem Text="请选择" Value="0" meta:resourcekey="ListItemResource1"></asp:ListItem>
        <asp:ListItem Text="中文简体" Value="1" meta:resourcekey="ListItemResource2"></asp:ListItem>
        <asp:ListItem Text="中文繁体" Value="2" meta:resourcekey="ListItemResource3"></asp:ListItem>
    </asp:DropDownList>
    </div>
    </form>
</body>
</html>

注意:将 Culture="auto" 和UICulture="auto" 如果让浏览器选择语系则留着,如果后台代码选择语系则必须去掉。

然后将WebForm1.aspx.resx复制然后黏贴改名

其他需要注意的比较多,目前注意到的如下:

  1.单独的文字使用控件Localize来替换

<asp:Localize ID="Localize1" runat="server" Text="单独的字体"></asp:Localize>

  2.服务器控件 DropDownList 的 ListItem 需要设置Value属性,否则会默认为Text值(不设置Value属性js取值value为Text值)。

 

哎!还有的没写出来。回家了。

  年后回来继续。

 

 

 

 

转载于:https://www.cnblogs.com/kim01/archive/2013/02/07/2908877.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值