Master pages: Page_Load is backwards

B

Brian

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!
 
G

Guest

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

Chris Fulstow

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
 
B

Brian

Larry Charlton said:
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!
 
Joined
Jan 6, 2009
Messages
1
Reaction score
0
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top