Link to home
Start Free TrialLog in
Avatar of TinoNL
TinoNL

asked on

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
        Me.Controls.Add(myButton)
    End Sub
End Class

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gyanendra Singh
Gyanendra Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TinoNL
TinoNL

ASKER

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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TinoNL

ASKER

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.
 

My.Resources.FooterControl.btn_Save

Open in new window

ye ... that's why we called them gloabal resource ... . i am glad that you find a way .. all the best
Avatar of TinoNL

ASKER

Thanks for the help man!