从asp.net 4中的Resource文件获取文本

时间:2012-12-12 21:31:34

标签: asp.net localization resource-file

我有一个asp.net网页,其中包含一个标签,现在我想从localresource文件中获取标签的text属性,我在.resx文件夹下有一个App_LocalResources文件,我的UserNameLabel.Text文件中包含名称为User Name,值为aspx我正在使用此Label控件

<asp:Label ID="UserNameLabel" runat="server" resourcekey="UserNameLabel"></asp:Label>

但我无法获取标签上的文字,任何人都可以告诉我从资源文件添加文本属性的正确方法

1 个答案:

答案 0 :(得分:4)

首先,您需要在Web项目中创建适当的结构。在这种情况下,我将使用Default.aspx:

enter image description here

注意我已将Default.aspx.resx文件放在App_LocalResources中。

接下来在Default.aspx.resx中输入新项目,如下所示:

enter image description here

重要的是你需要设置Text属性(UserNameLabel.Text)

最后这里是aspx代码:

<asp:Label ID="UserNameLabel" runat="server" meta:resourcekey="UserNameLabel"></asp:Label>

我使用meta:resourcekey链接到适当的资源键。