Master pages: Page_Load is backwards

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brian

    Master pages: Page_Load is backwards

    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!


  • Larry Charlton

    #2
    RE: Master pages: Page_Load is backwards

    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.

    Comment

    • Chris Fulstow

      #3
      Re: Master pages: Page_Load is backwards

      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

      Comment

      • Brian

        #4
        Re: Master pages: Page_Load is backwards

        "Larry Charlton" <LarryCharlton@ discussions.mic rosoft.com> wrote in message
        news:43EC60C3-3E53-4F10-81AF-FB0CF887F04D@mi crosoft.com...[color=blue]
        > 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.[/color]

        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_Lo ad() is executed
        which queries the order table, Master.Page_Loa d() is executed which notices
        the user isn't logged in and redirects to Login.aspx?retu rnurl=orders. The
        Content.Page_Lo ad() 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!



        Comment

        Working...