与发行对象GetLocalResource [英] Issue with GetLocalResource object
问题描述
我试图访问我的本地资源文件在我的code-后面。我做了一些谷歌上搜索,因为我是不确定如何做到这一点,发现这一点:
I am trying to access my local resources file in my code-behind. I did some googling since I was unsure of how to do it and found this:
oContent.Text = HttpContext.GetLocalResourceObject("NonSupport").ToString();
不过,我得到一个错误说,它至少需要两个参数: VirtualPath
和的ResourceKey
。还有第三个,的CultureInfo
,但一个是可选的。当我把这个作为我的虚拟路径:
However, I get an error saying that it needs at least two parameters: VirtualPath
and ResourceKey
. There is a third, CultureInfo
but that one is optional. When I put this in as my virtual path:
HttpContext.GetLocalResourceObject("App_LocalResources/ExpandableListView.aspx.resx", "NonSupport").ToString();
我得到以下编译器错误消息:
I get the following compiler error message:
相对虚拟路径App_LocalResources文件/ ExpandableListView.aspx.resx在这里不允许。
The relative virtual path 'App_LocalResources/ExpandableListView.aspx.resx' is not allowed here.
我必须做一些不对的,因为我的搜索(和一些帖子,我发现放在这里)说,所有我需要做的就是调用的资源键。
I must be doing something wrong with this since my searches (and some posts I found on here) say all I need to do is call the resource key.
有什么想法?谢谢!
推荐答案
你把一个资源文件名为(您的ASPX网页).aspx.resx
进入一个 App_LocalResource
在您的ASPX页面的生活??路径下的文件夹
Did you put a resource file with the name (your aspx web page).aspx.resx
into a App_LocalResource
folder underneath the path where your ASPX page lives??
此外,只需简单地调用 GetLocalResourceObject
法在当前页面上:
Furthermore, just simply call the GetLocalResourceObject
method on your current page:
oContent.Text = GetLocalResourceObject("NonSupport").ToString();
没有必要使用的HttpContext为 - 该方法被定义在页
类
No need to use HttpContext for that - the method is defined on the Page
class.
马克
这篇关于与发行对象GetLocalResource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!