Master pages: Page_Load is backwards

Discussion in 'ASP .Net' started by Brian, Apr 9, 2006.

  1. Brian

    Brian Guest

    Master pages run Page_Load() from the deepest level of nesting outwards. So
    if I write a content page based on a nested master which is then based on
    some other master, the Page_Loads are executed backwards:
    Content page, SubMaster Page, Master Page.

    Does this seem messed up to anyone else?? I can't see any logic in this.
    But from what I understand, the whole master page scheme is cooked on top of
    the usercontrol class. So the "master" really is a control in the content
    page.

    Any ideas for reversing the order of execution?

    Thanks!
    Brian, Apr 9, 2006
    #1
    1. Advertising

  2. No ideas on reversing them. Conceptually it make sense if you think of the
    content page as being the real page that the master gets added to. If you
    have a super master then it would get added to that master so from a call
    chain it makes sense that you start with the content then call it's master
    and then call it's master.

    What are you trying to do? In general you'll have much better luck if you
    always assume an event could always happen at a random time and in a random
    order.
    =?Utf-8?B?TGFycnkgQ2hhcmx0b24=?=, Apr 9, 2006
    #2
    1. Advertising

  3. I agree with Larry, I think it makes sense that the content page's load
    event fires first, and it then gets 'decorated' with the master page.
    However, you have to be really careful with some other events, because
    they fire the other way around: master page first.

    This is the sequence of events that get fired when a content page is
    merged with a master:

    Master page controls Init event
    Content controls Init event

    Master page Init event
    Content page Init event

    Content page Load event
    Master page Load event

    Content page PreRender event
    Master page PreRender event

    Master page controls PreRender event
    Content controls PreRender event

    HTH,

    Chris
    Chris Fulstow, Apr 9, 2006
    #3
  4. Brian

    Brian Guest

    "Larry Charlton" <> wrote in message
    news:...
    > No ideas on reversing them. Conceptually it make sense if you think of
    > the
    > content page as being the real page that the master gets added to. If you
    > have a super master then it would get added to that master so from a call
    > chain it makes sense that you start with the content then call it's master
    > and then call it's master.
    >
    > What are you trying to do? In general you'll have much better luck if you
    > always assume an event could always happen at a random time and in a
    > random
    > order.


    Hi Larry and Chris -

    Thanks for the replies. I had the mindset that the master page and content
    page have the same relationship as a derived and base class. I see what
    you're saying about the 'added to' philosophy. Makes much more sense now,
    thanks.

    I'm trying to implement security. The page_load of a master page seemed a
    convenient way to add security to a large group of web pages. The page_load
    checks the users session and redirects to a login page if the user isn't
    logged in. The login page is also passed a return url.

    It works in a practical sense. The end result is what I want. But too many
    page_load methods are being called and the extra processing is thrown away.

    Here's an example:
    User opens "Orders" page (requires login), Content.Page_Load() is executed
    which queries the order table, Master.Page_Load() is executed which notices
    the user isn't logged in and redirects to Login.aspx?returnurl=orders. The
    Content.Page_Load() is needlessly executed.

    I'm probably trying to reinvent the wheel with security. Is there something
    precanned that will do the login stuff and the return url?

    Thanks!
    Brian, Apr 10, 2006
    #4
  5. Brian

    abundantlife1010

    Joined:
    Jan 6, 2009
    Messages:
    1
    Possible Solution

    Hello,

    I know the original poster has long finished his project, but I thought it might help someone else who comes across this thread in the future.

    One possible solution to ensuring that the page_load event doesn't fire unnecessarily before the user is authenticated, is to place a Setup() function that checks for authenticity prior to your BindData() functionality. If the user is not authenticated, redirect to login. If authenticated, proceed to BindData().

    Hope this helps someone.

    In Him,
    John
    abundantlife1010, Jan 6, 2009
    #5
    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. Electrified Research
    Replies:
    5
    Views:
    2,443
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN
    Oct 11, 2005
  2. Doug McCann
    Replies:
    1
    Views:
    991
    William Brogden
    Aug 5, 2004
  3. Replies:
    1
    Views:
    3,189
    PeterKellner
    May 16, 2006
  4. Sam
    Replies:
    0
    Views:
    693
  5. Sam
    Replies:
    1
    Views:
    762
Loading...

Share This Page