vs 2005 多語言
新的资源绑定语法
<asp:Button ID=Button1 Text='<%$ Resources:test1, Button1Text, "HelloWorld" %>' OnClick="Button1_Click" runat=server />
这是 Asp.Net 的多语言方案了。
<%$ Resources:test1, Button1Text, "HelloWorld" %> 的意思是
从 Resources 或 Code 中得到 test1 这个 resx 中的 Button1Text 的字符串, 而 "HelloWrod" 则作为设计时的资源。
我在 Resources/test1.resx 内添加了 Button1Text ,值是 "你好!" 然后就显示出来了:)
<%$ Code:"HelloWorld" %>
->
Parser Error Message: The expression prefix 'Code' was not recognized. Please correct the prefix or register the prefix in the <expressionBuilders> section of configuration.
<expressionBuilders> 在 <compilation> 下
<compilation debug="true">
<expressionBuilders>
<add expressionPrefix="MyExp" type="MyExpBuidler"/>
</expressionBuilders>
</compilation>
<asp:Button ID=Button2 Text='<%$ MyExp : HelloWorld %>' OnClick="Button1_Click" runat=server />
using System;
using System.CodeDom;
using System.Collections;
using System.Web;
using System.Web.Compilation;
public class MyExpBuilder : System.Web.Compilation.ExpressionBuilder
{
public override System.CodeDom.CodeExpression GetCodeExpression(System.Web.UI.BoundPropertyEntry entry, object parsedData, System.Web.Compilation.ExpressionBuilderContext context)
{
return new System.CodeDom.CodePrimitiveExpression("["+entry.Expression+"]");
}
}
得到 <input type="submit" name="Button2" value="[HelloWorld]" id="Button2" />
使用上,至少要 <asp:Literal Runat=server Text='<%$ MyExp : HelloWorld %>' />
[ExpressionEditor(typeof(MyExpBuilderEditor))]
[ExpressionPrefix("MyExp")]
public class MyExpBuilder : System.Web.Compilation.ExpressionBuilder
public class MyExpBuilderEditor : System.Web.UI.Design.ExpressionEditor
{
public override object EvaluateExpression(string expression, object parseTimeData, Type propertyType, IServiceProvider serviceProvider)
{
return expression + ":" + parseTimeData + ":" + propertyType + ":" + serviceProvider;
}
}
ExpressionBuilder 应该在另外的Assembly里放。否则VWD不认它。