DevT
DevT

Reputation: 4933

asp.net page life cycle in refresh

This seems to be very primary question, but I met lot of difficulties while implementing my program.

My program Structure is as follows: Details

I have 2 content page called News.aspx and Contact.aspx. these two pages contain user controls as well.

I have code for PreInit and Load in both .aspx page and user control contain Init method.

If user is currently in contact.aspx page and then he click on the link button to move to News.aspx page, what is the order of firing those events?

When i put break point and check then it comes in following order.

Contact.aspx  PreInit
Contact.aspx Init
News.aspx    PreInit
News.aspx    Init

but even though sometimes this works other way around. first News.aspx methods then abc.aspx page method.

What is the exact order? In addition to that using java script i called web method every page refresh in onbeforeunload. in the above scenario that method call as follows:

  Contact.aspx  PreInit
    Contact.aspx Init
    Web Method () on Page Refresh
    News.aspx    PreInit
    News.aspx    Init

What is the correct order of calling these methods?

Upvotes: 0

Views: 1318

Answers (1)

Halcyon
Halcyon

Reputation: 14971

This is the order of the life cycle events:

  1. News.aspx - Page_PreInit
  2. UserControl.ascx - Page_Init
  3. MasterPage.master - Page_Init
  4. News.aspx - Page_Init
  5. News.aspx - Page_Load
  6. MasterPage.master - Page_Load
  7. UserControl.ascx - Page_Load

The Page's PreInit event is triggered before the controls are initialized, so the user control does not have a PreInit event. Please see http://msdn.microsoft.com/en-us/library/ms178472.aspx.

Upvotes: 1

Related Questions