使用WebForms应用程序中的类库中的资源

时间:2015-12-06 15:25:38

标签: c# asp.net

在我的应用程序中,有一个类库项目和一个网站。我在类库中创建了一个资源文件,并且它的修饰符是public。我需要在网站层使用此资源:

<asp:Label ID="Label2" runat="server" Text="<%$ Resources:resourceName, ErrorEmptyName %>"></asp:Label>

但是显示错误:

  

带有键&#39; ErrorEmptyName&#39;的资源对象没找到。

但在代码隐藏中,我访问了这个密钥:

Label1.Text = resourceName.ErrorEmptyName;

并且没有错误。

我找到了这个页面,但我无法使用: Referencing resource files from multiple projects in a solution

有什么问题?怎么做?

1 个答案:

答案 0 :(得分:0)

您可以使用代码

<asp:Label ID="Label2" runat="server" Text="<%# resourceName.ErrorEmptyName %>"></asp:Label>

也许您需要导入命名空间。