Deduce calling Page or UserControl in library method

Discussion in 'ASP .Net' started by JezB, May 26, 2004.

  1. JezB

    JezB Guest

    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 ?
     
    JezB, May 26, 2004
    #1
    1. Advertising

  2. JezB

    Cowboy Guest

    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!
    ************************************************
    "JezB" <> wrote in message
    news:...
    > 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 ?
    >
    >
     
    Cowboy, May 26, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan Krantz
    Replies:
    3
    Views:
    436
    Howard Hinnant
    Jun 13, 2006
  2. Replies:
    7
    Views:
    543
  3. George2

    template function argument deduce

    George2, Mar 11, 2008, in forum: C Programming
    Replies:
    0
    Views:
    375
    George2
    Mar 11, 2008
  4. Ed
    Replies:
    1
    Views:
    400
    James Kanze
    Aug 14, 2008
  5. nguillot
    Replies:
    5
    Views:
    535
Loading...

Share This Page