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. Advertisements

  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. Advertisements

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. Ashutosh

    Calling UserControl public method

    Ashutosh, Jul 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    712
    Ed Kaim [MSFT]
    Jul 5, 2004
  2. Ashutosh

    Calling USERCONTROL public method

    Ashutosh, Jul 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    426
    John Saunders
    Jul 4, 2004
  3. Peter Rilling
    Replies:
    4
    Views:
    3,141
    TahirAhmadov
    Mar 25, 2009
  4. Dan Krantz
    Replies:
    3
    Views:
    596
    Howard Hinnant
    Jun 13, 2006
  5. Replies:
    7
    Views:
    761
  6. Chevron Boyde
    Replies:
    1
    Views:
    1,609
    George
    Dec 8, 2008
  7. nguillot
    Replies:
    5
    Views:
    819
  8. Replies:
    1
    Views:
    311
Loading...