惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Cisco Talos Blog
Cisco Talos Blog
V
V2EX
C
Check Point Blog
GbyAI
GbyAI
D
Docker
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
T
Troy Hunt's Blog
博客园 - Franky
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Security Blog
Microsoft Security Blog
P
Privacy & Cybersecurity Law Blog
WordPress大学
WordPress大学
The Cloudflare Blog
S
SegmentFault 最新的问题
Latest news
Latest news
Microsoft Azure Blog
Microsoft Azure Blog
P
Proofpoint News Feed
I
InfoQ
博客园 - 【当耐特】
NISL@THU
NISL@THU
A
About on SuperTechFans
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
The Hacker News
The Hacker News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Scott Helme
Scott Helme
雷峰网
雷峰网
C
CXSECURITY Database RSS Feed - CXSecurity.com
Security Latest
Security Latest
V
Vulnerabilities – Threatpost
Security Archives - TechRepublic
Security Archives - TechRepublic
A
Arctic Wolf
Hacker News: Ask HN
Hacker News: Ask HN
N
News and Events Feed by Topic
IT之家
IT之家
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
aimingoo的专栏
aimingoo的专栏
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
SecWiki News
SecWiki News
大猫的无限游戏
大猫的无限游戏
S
Security Affairs
The Register - Security
The Register - Security
www.infosecurity-magazine.com
www.infosecurity-magazine.com
L
LINUX DO - 热门话题
T
Tor Project blog

博客园 - 搞IT的狐狸

ASP.Net动态使用CSS - 搞IT的狐狸 - 博客园 SqlDataReader或DATATABLE DATASET 到EXCEL [转载]ROW_NUM实现分页 VS2005 TreeView 的 CheckBox 被点击时的引发页面回发事件 (转发) ASP.NET 2.0,C#----利用GridView控件导出其他文件(导出Excel,导出Word文件) 什么是SHTML 如何使用IFRAM JS来刷新UpdatePanel 随即验证码实现(根据韩现龙代码修改) [北京]招聘 网站设计师 我这半个月的代码总结(小技巧,小代码)之二 我这半个月的代码总结(小技巧,小代码)之一 用Themes实现网站换肤 将数据控件(如GridView)的内容转化成Excel格式文件 ASP.NET新手实用技巧!(C#) 学历不高!写给自己!自勉! 一张笑死我又让我辛酸的图片!开发人员的辛酸! 服务器刚开,凑个沙发!.NET几点你应该知道的细节! 求动态绑定控件ID的值的方法!着急!
(转载)ASP.NET本地化
搞IT的狐狸 · 2008-04-07 · via 博客园 - 搞IT的狐狸

譬如我有一个登陆页面,上面有两个Label和两个Textbox,页面命名为Login.aspx,控件命名为lbl_UserName,lbl_Password,txt_UserName,txt_Password。

首先可以在网站上新建一个App_LocalResources的文件夹,然后新建一个资源文件,命名为Login.aspx.resx
命名需要跟匹配的页面名字相同。然后再新建另一个资源文件,命名为Login.aspx.zh-Cn.resx

Login.aspx.resx 这个为默认的,而Login.aspx.zh-Cn.resx这个为当浏览器默认语言设为中文的时候调用的。

打开Login.aspx.resx文件:      
名称                             值

LabelResource1.Text   Username
LabelResource2.Text   Password

打开Login.aspx.zh-Cn.resx文件:
名称                                值:

LabelResource1.Text    用户名
LabelResource2.Text 密码

然后,在我们的页面代码中

1<asp:Label ID="lbl_UserName" runat="server"></asp:Label>
2<asp:Label ID="lbl_Password" runat="server"></asp:Label>

改为

1<asp:Label ID="lbl_UserName" runat="server" Text="<%$ Resources:LabelResource1.Text %>"></asp:Label>
2<asp:Label ID="lbl_Password" runat="server"  Text="<%$ Resources:LabelResource2.Text %>"></asp:Label>
3

最后,在页面的Page属性中,加上 Culture="auto:zh-Cn" UICulture="auto:zh-Cn" ,默认设为了中文。

编译便可以看到效果,当浏览器默认语言为英文时,可以看到两个Label的显示为Username和Password。
当浏览器默认语言为中文时,可以看到两个Label的显示为用户名和密码。

-------------------------------自己新写的---------------------------------------------------------
ASP.NET里不需要这么麻烦

也不需要编译了

HttpContext.GetGlobalResourceObject("资源文件名(不写扩展名)", "要取的ID(标记)");
一句话搞定