views:

763

answers:

1

Hey SO:

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();

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:

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.

Any thoughts? Thanks!

+2  A: 

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??

Furthermore, just simply call the GetLocalResourceObject method on your current page:

oContent.Text = GetLocalResourceObject("NonSupport").ToString();

No need to use HttpContext for that - the method is defined on the Page class.

Marc

marc_s
Yes. I added an asp.net folder (App_LocalResources) into the directory where this aspx file resides.
Anders
OK - did you use the Visual Studio "Add ASP.NET folder" method?
marc_s
Yep. Right clicked on the parent folder, selected "Add ASP.NET folder..." then selected the local resource one
Anders
Thanks. The underlying problem was my class was declared static (dunno why it was there, maybe ReSharper added it) and the GetLocalResourceObject cannot be accessed inside of a static context.
Anders
OK, glad you found the culprit and a solution for it!
marc_s