• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1211
  • Last Modified:

How can I access values in the Resource .resx file that is attached to custom control?

I have a directory called Controls. This folder contains all my custom controls.  To keep things nice and tidy, I also placed my resource files there. These resource files don't have to be application wide available through the app_GlobalResources folder, but only to the custom control.

There is a (simple) custom control called FooterControl.vb. When I add a resource file with the name FooterControl.resx, this is displayed as a child of the footercontrol.

In the Resource file, there is a value for btnSave, that contains the translation that should be displayed on the Text label. But when I want to assign the value I get stuck. Resources.FooterControl.btnSave doesn't work.
<DefaultProperty("Text"), ToolboxData("<{0}:FooterControl runat=server></{0}:FooterControl>")> _
    Public Class FooterControl
    Inherits WebControl
    Implements INamingContainer
    Implements IComponent
    Protected Overrides Sub CreateChildControls()
        Dim myButton As New Button
        myButton.Text = Resources.FooterControl.btnSave
    End Sub
End Class

Open in new window

  • 3
  • 3
2 Solutions
Gyanendra SinghArchitectCommented:
try this
globalresourcestring = (String)GetGlobalResourceObject("MyResource", "GlobalResourceString1");

in vb.net i guess it like

globalresourcestring = DirectCast(GetGlobalResourceObject("MyResource", "GlobalResourceString1"), String)

here MyResource is your resource file name
TinoNLAuthor Commented:
I'm afraid this doesn't work from a custom control. In a CC it should be something like:
HttpContext.GetGlobalResourceObject("FooterControl", "btn_Save")
It gives the error:
Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "Resources.FooterControl.resources" was correctly embedded or linked into assembly "App_GlobalResources.iijgpt85" at compile time, or that all the satellite assemblies required are loadable and fully signed.
So then I tried approaching the file through the local object:

HttpContext.GetLocalResourceObject("FooterControl", "btn_Delete")
It throws the error:
The relative virtual path 'FooterControl' is not allowed here.
Gyanendra SinghArchitectCommented:
you are right... you are very near to solution :)  i guss problem in namespace difference between your control in aspx page

so use this
HttpContext.GetGlobalResourceObject("[Namespace.]ClassKey", "btn_Save")

so provide fully qualified name

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

TinoNLAuthor Commented:
Nah; it looks like the globalresourceobject only works when your resx files reside in the app_GlobalResources folder?
But it brought me the idea to explore the class view a little bit further and found the solution myself.
Thanks for leading me this way.


Open in new window

Gyanendra SinghArchitectCommented:
ye ... that's why we called them gloabal resource ... . i am glad that you find a way .. all the best
TinoNLAuthor Commented:
Thanks for the help man!

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now