Does master page get called first?

南楼画角 提交于 2019-12-03 05:19:46

问题


I would assume this is true, but wanted to throw this question up. Is the master page executed first in ASP.NET, or does the page which is getting retrieved?

I am asking because I want some processing to be done in the master page, results of which are loaded into a static object and which can then be used by the called page (for instance user data)


回答1:


Sorry for just quoting, but i don't know what to add:

Individual ASP.NET server controls have their own life cycle that is similar to the page life cycle. For example, a control's Init and Load events occur during the corresponding page events.

Although both Init and Load recursively occur on each control, they happen in reverse order. The Init event (and also the Unload event) for each child control occur before the corresponding event is raised for its container (bottom-up). However the Load event for a container occurs before the Load events for its child controls (top-down). Master pages behave like child controls on a page: the master page Init event occurs before the page Init and Load events, and the master page Load event occurs after the page Init and Load events.

http://msdn.microsoft.com/en-us/library/ms178472.aspx




回答2:


Execution Priority

  1. Content Page
  2. Master Page
  3. User Control



回答3:


Most page events will get called before the corresponding ones on the master page are (in essence the master page is considered a part of the page it is linked to - it is a user control).

See ASP.Net 2.0 - Master Pages: Tips, Tricks, and Traps on OdeToCode for details.




回答4:


you could look at the .net documentation which states when and in what order events are called

see this, this and this



来源:https://stackoverflow.com/questions/10505350/does-master-page-get-called-first

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!