开发者

Programmatically localize a String?

Asp.net 4 and C#.

I have a string in my Code Behind. I would like assign a value depending on the User's Browser region.

I'm trying with this code, no error, but does not work (no value to a String has bee开发者_StackOverflow中文版n assigned).

Any idea how to solve it? Thanks

   string textPrevious = "<%$ Resources:Global, CategoryListSubCategories %>";


I found out the solution myself: Just use Resources.Global.

string textPrevious = Resources.Global.CategoryListSubCategories;

Useful article: http://shan-tech.blogspot.com/2007/02/aspnet-20-localization-of-string.html


You can do like...

string textPrevious = Resources.Global.CategoryListSubCategories;


You can build an ExpressionBuilder to access the code-behind string. The article .NET String Resources includes the class StringExpressionBuilder with the expression Strings:

<asp:Label ID="AppTextLabel" runat="server" 
    Text="<%$ Strings:MyCompany.MyApp.MyStrings, AppText %>" />
<asp:Label ID="LibTextLabel" runat="server" 
    Text="<%$ Strings:MyCompany.MyLib.MyStrings, LibText %>" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜