Deduce calling Page or UserControl in library method

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