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

TinoNLAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
0
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



0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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.
 

My.Resources.FooterControl.btn_Save

Open in new window

0
Gyanendra SinghArchitectCommented:
ye ... that's why we called them gloabal resource ... . i am glad that you find a way .. all the best
0
TinoNLAuthor Commented:
Thanks for the help man!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.