如何从ASP.NET页访问Resource.resx? [英] How to access to a Resource.resx from ASP.NET page?

查看:44
本文介绍了如何从ASP.NET页访问Resource.resx?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从ASP.NET页面访问资源文件.我有一个名为"Resources"的文件夹,其中包含与页面相同级别的文件"WebResources.resx".生成的WebResources.Designer.cs中公共类的名称也为"WebResources"我页面的名称是"formulargenerator.aspx".来自后台代码的访问非常有效.我可以通过2种方式访问​​:

I would like to access a resource-file from ASP.NET page. I have a folder named "Resources" containing the file "WebResources.resx" on the same level as the page. The name of the public class in the generated WebResources.Designer.cs is also "WebResources" My page's name is "formulargenerator.aspx". Access from code-behind works perfectly. I can access in 2 ways:

ResourceManager rm = new ResourceManager(typeof(WebResources));
string val = rm.GetString("Key");

string val = WebResources.Key;

但是,如果我不想重命名资源文件,如何直接从页面访问?我试图使用文件夹App_LocalResources-无法访问.仅当资源文件的名称与页面相同时,它才起作用.访问资源的语法如何?下面的代码不起作用.必须/可以导入名称空间吗?

But how can I access from page directly if I don't like to rename the Resource-file? I have tried to use the folder App_LocalResources - no access. Only if the resource-file is named like the page does it work. How is the syntax to access a ressource? The code below doesn't work. Must/Can I import a namespace?

<asp:Label Text="<%$Resources: WebResources, Key%>" runat="server" />

事先考虑

推荐答案

您可能想看看 ASP.NET网页资源概述.本地资源特定于具体的aspx页面,并且使用与全局应用程序资源不同的命名约定.如果使用全局资源,则您正在使用的资源标签更有可能起作用.

You might want to take look at ASP.NET Web Page Resources Overview. Local resources are specific to a concrete aspx page and use a different naming convention than global application resources. The resource tag you are using is more-likely to work if using global resources.

这篇关于如何从ASP.NET页访问Resource.resx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆