全局资源访问:
使用下面的格式来定位全局资源
<%$ resources: [applicationkey], resourcekey%>
比如从glossary.resx读取资源例子如下
<asp:imagebutton id="btnidesign" runat="server" imageurl="~/images/idesignlogo.jpg"
alternatetext='<%$ resources:glossary, missionsatatement%>'
postbackurl="http://www.idesign.net" meta:resourcekey="imagebuttonresource1" />
当然你也可以直接用ide的表达式对话框直接来选择
用程序读取方式如下:
imagebutton button1 = new imagebutton();
// other initialization code
button1.id = "btnidesign";
button1.accesskey = (string) base.getlocalresourceobject("imagebuttonresource1.accesskey");
button1.alternatetext = (string) base.getglobalresourceobject("glossary", "missionstatement");
button1.imageurl = (string) base.getlocalresourceobject("imagebuttonresource1.imageurl");
button1.tooltip = (string) base.getlocalresourceobject("imagebuttonresource1.tooltip");
button1.visible = (bool)
base.getlocalresourceobject("imagebuttonresource1.visible", typeof(control), "visible");
本地化html控件和文本:
html控件:html控件不能用前面说的两种表达式来指定资源,除非是让它runat=server,不过对于页面的title比较特殊,它也会作为页面的一个对象自动生成本地资源
<%@ page language="c#" codefile="default.aspx.cs" inherits="_default" meta:resourcekey="pageresource1" %>
不过,我们也可以为它制定全局资源
<head runat="server">
<title>
<asp:literal text='<% $ resources: glossary, defaultpagetitle %>' runat="server"></asp:literal>
</title>
</head>
本地化文本:
对于项目中很多静态的文本,我们可以使用localize控件来包含这些文字,其实这个控件和literal相似,但是它能在设计模式下随意修改里面的文字内容,看下怎么访问本地资源和全局资源
<asp:localize id="welcomecontent" runat="server" meta:resourcekey="welcome">welcome!</asp:localize>
<asp:localize id="welcomecontent" runat="server" text='<%$ resources: glossary,
welcometext%>'>welcome!</asp:localize>
多语言实现:
从默认的资源文件复制一个新的的资源文件,只要在resx前面加上地区代号,逐项编辑即可,如下设置后浏览器会自动根据设置(工具-选项-语言)调用新的资源文件
<%@ page uiculture="auto" culture="auto">
当然你也可以通过web.config文件指定一种语言
<system.web>
<globalization culture="es-es" uiculture="es">
</system.web>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器