Access Page's local resource from user control

  • Thread starter Thread starter schneider
  • Start date Start date
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
 
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!
 
Back
Top