UserControl awareness of calling page

Discussion in 'ASP .Net' started by MattB, Jan 22, 2004.

  1. MattB

    MattB Guest

    I have a UserControl that I use as a page header for my app. I want it to
    vary depending on what page it's being called by. In the CodeBehind, how to
    I refer to the calling page? Thanks!

    --

    Matt

    "Gravity. It's not just a good idea, it's the law!"
    MattB, Jan 22, 2004
    #1
    1. Advertising

  2. MattB

    MattB Guest

    MattB wrote:
    > I have a UserControl that I use as a page header for my app. I want
    > it to vary depending on what page it's being called by. In the
    > CodeBehind, how to I refer to the calling page? Thanks!


    Oh, and this is vb.net in the codebehind, BTW.

    Matt
    MattB, Jan 22, 2004
    #2
    1. Advertising

  3. MattB

    Guogang Guest

    Page p = this.Page;

    You can create a base class or interface for all your pages, so that you
    have a uniformed way to knowing what to be shown in the header.

    "MattB" <> wrote in message
    news:bupa6f$k6065$-berlin.de...
    > I have a UserControl that I use as a page header for my app. I want it to
    > vary depending on what page it's being called by. In the CodeBehind, how

    to
    > I refer to the calling page? Thanks!
    >
    > --
    >
    > Matt
    >
    > "Gravity. It's not just a good idea, it's the law!"
    >
    >
    Guogang, Jan 22, 2004
    #3
  4. MattB

    Teemu Keiski Guest

    Hi,

    via the Page property of the user control. Just cast the Page property to
    the code-behind type of the Page (if what you are accessing is declared
    there) and off you go. Just note that this of course limits bit the
    reusability of the user control as it needs to know on what page it is
    used(when you are casting). If you don't need to get anything from Page's
    code-behind type, you can just use the Page property (it is of type
    System.Web.UI.Page) and then it, of course, does not limit the reusability.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist


    "MattB" <> wrote in message
    news:bupa6f$k6065$-berlin.de...
    >I have a UserControl that I use as a page header for my app. I want it to
    > vary depending on what page it's being called by. In the CodeBehind, how
    > to
    > I refer to the calling page? Thanks!
    >
    > --
    >
    > Matt
    >
    > "Gravity. It's not just a good idea, it's the law!"
    >
    >
    Teemu Keiski, Jan 22, 2004
    #4
    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. Martin M.
    Replies:
    4
    Views:
    333
    Simon Brunning
    Dec 15, 2005
  2. adeelmahmood
    Replies:
    11
    Views:
    889
    Alex Hunsley
    Feb 15, 2007
  3. makarand
    Replies:
    0
    Views:
    466
    makarand
    Jul 7, 2008
  4. Mohamed Yousef
    Replies:
    0
    Views:
    213
    Mohamed Yousef
    Aug 23, 2008
  5. alex23
    Replies:
    3
    Views:
    229
    Fredrik Lundh
    Aug 24, 2008
Loading...

Share This Page