Access Page's local resource from user control

S

schneider

Is it possible to get access to the local resource
(App_LocalResources) of an aspx page from within a user control
located somewhere else? I have created a user control which I want to
add to a page and read values from the page's local resource. But
within the code of the user control, I can only access the local
resource of the user control itself in its own App_LocalResources
folder.
Can someone help me please?

Cheers, Hannes
 
S

schneider

Is it possible to get access to the local resource
(App_LocalResources) of an aspx page from within a user control
located somewhere else? I have created a user control which I want to
add to a page and read values from the page's local resource. But
within the code of the user control, I can only access the local
resource of the user control itself in its own App_LocalResources
folder.
Can someone help me please?

Cheers, Hannes


I found a satisfactory solution myself: The magic word is "delegate".
For those who are interested, here's some sample code. It is very easy
to implement.

In the content page's master page respectively the user control it
contains you put the delegate declaration:

public delegate object GetPageLocalResourceObject(string
resourceKey); // the delegate declaration itself
public GetPageLocalResourceObject LoadLocalPageResource; // public
instance of the delegate to be set by the content page

Now in every content page, you have to put one or both of the
following lines into its Page_Load function (depending on whether you
use a master page or a user control or both):

<Instance of the User Control>.LoadLocalPageResource =
GetLocalResourceObject; // set the user control's delegate instance to
my own GetLocalResourceObject function
Master.LoadLocalPageResource = GetLocalResourceObject; // set the
master page's delegate instance to my own GetLocalResourceObject
function

HTH!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top