32

I have an aspx and inside it an ascx. From a short testing I see the PageLoad of the aspx is called before the PageLoad of the user-Control but the opposite is true for OnInit.

Does someone know what is the order of the events (page compared to a user-control inside it)

Thanks

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

2 Answers2

88

You should look at this ASP.NET Page Life Cycle Overview and this

Page: PreInit
Control: Init
Page: Init
Page: InitComplete
Page: PreLoad
Page: Load
Control: Load
Page: LoadComplete
Page: PreRender
Control: PreRender
Page: PreRenderComplete
Page: SaveStateComplete
Page: RenderControl
Page: Render
Control: RenderControl
Control: Unload
Control: Dispose
Page: Unload
Page: Dispose

krolik
  • 5,712
  • 1
  • 26
  • 30
  • 1
    Good resource, but it's encouraged for you to summarize some info / asnwer the OP's question in the Answer you've posted. Just in case the link ever dies, this information will be there for future searchers – Josh Darnell Sep 07 '11 at 14:10
  • I have ready your first link. I ask about the order of the events of the page compared to the events of the control inside it. – Elad Benda Sep 07 '11 at 14:17
  • I've updated the answer with more details. Is that what you want? – krolik Sep 07 '11 at 14:34
  • amazing! Does it also appear in the links you have posted? If not- where did you take it from? – Elad Benda Sep 07 '11 at 17:38
  • 1
    I get it from.. my bookmarks. [Application, Page and Control events in ASP.NET v2.0](http://weblogs.asp.net/jeff/archive/2004/07/04/172683.aspx) – krolik Sep 07 '11 at 21:28
  • same logic for a user-control inside another user-control ? – Elad Benda Sep 08 '11 at 08:29
  • Missing `LoadViewState ` check http://msdn.microsoft.com/en-us/library/aa719775%28v=vs.71%29.aspx – Murali Murugesan Oct 01 '13 at 11:36
  • @EladBenda [ASP.NET Page Life Cycle Overview](http://msdn.microsoft.com/en-us/library/ms178472.ASPX) says, "The Page object calls the OnLoad method on the Page object, and then recursively does the same for each child control until the page and all controls are loaded. The Load event of individual controls occurs after the Load event of the page. Use the OnLoad event method to set properties in controls and to establish database connections." – ChrisW Nov 10 '13 at 21:30
  • Missing control Page_load – DavidB Apr 24 '14 at 14:48
  • SaveViewState is also missing – BornToCode Dec 18 '14 at 07:08
3

below link has more information

http://weblogs.asp.net/ricardoperes/archive/2009/03/08/asp-net-page-events-lifecycle.aspx

chamara iresh
  • 217
  • 1
  • 13
  • 3
    Link only answers are discuraged by the site policy. Please, take time to extract the relevant information and add it to the question, since the URL can break at any time and this answer will lose it's value. – Ricardo Souza Jun 26 '15 at 18:22