Deduce calling Page or UserControl in library method

J

JezB

In my Page_Load event of all my web app Pages and UserControls I instantiate
the same library class "TextResources" (to take care of reading presentation
text strings from localizable resource files).

Within this class's constructor I want to deduce the name of the calling
control without having to pass it in. As this can either be a Page or a
UserControl I cannot use Request.URL since this only gives you the current
page.

Any ideas ?
 
C

Cowboy

I know of no way to accomplish this, so I am going to suggest what you are
trying not to do (apologies, although the method may be slightly different
than you were thinking). My suggestion is to create another constructor and
try something like:

public MyClass(object caller)
{
}

and call like so:

MyClass mc = new MyClass(this);

You can then determine the page or control calling the class.

I took a little time to experiment and I cannot find a way of either
a) deriving from a class that knows its container
b) determining calling assembly from runtime

If there is a way, reflection is probably where it is located.

Good luck!

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top