GetLocalResource对象的问题

And*_*ers 1 c# asp.net resources

我试图在我的代码隐藏中访问我的本地资源文件.我做了一些谷歌搜索,因为我不知道该怎么做,发现这个:

oContent.Text = HttpContext.GetLocalResourceObject("NonSupport").ToString();
Run Code Online (Sandbox Code Playgroud)

但是,我得到一个错误,说它至少需要两个参数:VirtualPathResourceKey.还有第三个,CultureInfo但那个是可选的.当我把它作为我的虚拟路径时:

HttpContext.GetLocalResourceObject("App_LocalResources/ExpandableListView.aspx.resx", "NonSupport").ToString();
Run Code Online (Sandbox Code Playgroud)

我收到以下编译器错误消息:

此处不允许使用相对虚拟路径"App_LocalResources/ExpandableListView.aspx.resx".

我必须做错了,因为我的搜索(以及我在这里发现的一些帖子)说我需要做的就是调用资源键.

有什么想法吗?谢谢!

mar*_*c_s 5

您是否将带有名称的资源文件放在ASPX页面所在路径下(your aspx web page).aspx.resxApp_LocalResource文件夹中?

此外,只需GetLocalResourceObject在当前页面上调用该方法:

oContent.Text = GetLocalResourceObject("NonSupport").ToString();
Run Code Online (Sandbox Code Playgroud)

不需要使用HttpContext - 该方法是在Page类上定义的.