ASP .Net Page Life Cycle

Explain the life cycle of an ASP .NET page.

Questions by reenu1210

Editorial / Best Answer

aanand_agrawal  

  • Member Since Apr-2009 | Apr 30th, 2009


1. OnInit (Init) Initializes each child control of the current

2. LoadControlState: Loads the ControlState of the control. To use this method, the control must call the Page.RegisterRequiresControlState method in the OnInit method of the control.

3. LoadViewState: Loads the ViewState of the control.

4. LoadPostData: Is defined on interface IPostBackDataHandler. Controls that implement this interface use this method to retrieve the incoming form data and update the control’s properties accordingly.

5. Load (OnLoad): Allows actions that are common to every request to be placed here. Note that the control is stable at this time; it has been initialized and its state has been reconstructed.

6. RaisePostDataChangedEvent: Is defined on the interface IPostBackData-Handler. Controls that implement this interface use this event to raise change events in response to the Postback data changing between the current Postback and the previous Postback. For example, if a TextBox has a TextChanged event and AutoPostback is turned off, clicking a button causes the Text-Changed event to execute in this stage before handling the click event of the button, which is raised in the next stage.

7. RaisePostbackEvent: Handles the client-side event that caused the Postback to occur

8. PreRender (OnPreRender): Allows last-minute changes to the control. This event takes place after all regular Post-back events have taken place. This event takes place before saving ViewState, so any changes made here are saved.

9. SaveControlState: Saves the current control state to ViewState. After this stage, any changes to the control state are lost. To use this method, the control must call the Page.RegisterRequiresControlState method in the OnInit method of the control.

10. SaveViewState: Saves the current data state of the control to ViewState. After this stage, any changes to the control data are lost.

11. Render: Generates the client-side HTML, Dynamic Hypertext Markup Language (DHTML), and script that are necessary to properly display this control at the browser. In this stage, any changes to the control are not persisted into ViewState.

12. Dispose: Accepts cleanup code. Releases any unman-aged resources in this stage. Unmanaged resources are resources that are not handled by the .NET common language runtime, such as file handles and database connections.

13. UnLoad

Showing Answers 1 - 60 of 60 Answers

1. OnInit (Init) Initializes each child control of the current


2. LoadControlState: Loads the ControlState of the control. To use this
method, the control must call the Page.RegisterRequiresControlState method in
the OnInit method of the control.


3. LoadViewState: Loads the ViewState of the control.


4. LoadPostData: Is defined on interface IPostBackDataHandler. Controls that
implement this interface use this method to retrieve the incoming form data and
update the control’s properties accordingly.


5. Load (OnLoad): Allows actions that are common to every request to be
placed here. Note that the control is stable at this time; it has been
initialized and its state has been reconstructed.


6. RaisePostDataChangedEvent: Is defined on the interface IPostBackData-Handler.
Controls that implement this interface use this event to raise change events in
response to the Postback data changing between the current Postback and the
previous Postback. For example, if a TextBox has a TextChanged event and
AutoPostback is turned off, clicking a button causes the Text-Changed event to
execute in this stage before handling the click event of the button, which is
raised in the next stage.


7. RaisePostbackEvent: Handles the client-side event that caused the Postback
to occur


8. PreRender (OnPreRender): Allows last-minute changes to the control. This
event takes place after all regular Post-back events have taken place. This
event takes place before saving ViewState, so any changes made here are saved.


9. SaveControlState: Saves the current control state to ViewState. After this
stage, any changes to the control state are lost. To use this method, the
control must call the Page.RegisterRequiresControlState method in the OnInit
method of the control.


10. SaveViewState: Saves the current data state of the control to ViewState.
After this stage, any changes to the control data are lost.


11. Render: Generates the client-side HTML, Dynamic Hypertext Markup Language
(DHTML), and script that are necessary to properly display this control at the
browser. In this stage, any changes to the control are not persisted into
ViewState.


12. Dispose: Accepts cleanup code. Releases any unman-aged resources in this
stage. Unmanaged resources are resources that are not handled by the .NET common
language runtime, such as file handles and database connections.


13. UnLoad

1. Page Request
2. Start
3. Page Initialization
4. Load
5. Validation
6. Postback and event Handling
7. Rendering
8. Unload


For The Page Execution Life Cycle Just Remember SILVER.
S-Start
I-Page Initialization
L-Load
V-Validation
E-Postback event handling
R-Rendering

sathin

  • Aug 24th, 2009
 

Set of subprograms that are executed towards each time of web page processing
are called "page life cycle events"


Page Preinit
This will be executed before memory initialization for web page [before
constructing web page]
Attaching theme, master page dynamically to webpage is possible using preinit
event proc


Page init
This will be executed when memory is initialized for webpage


Page load
This will be executed when submitted data and controls are loaded
Database connectivity, reading submitted data can be placed within pageload


PagePrerender
This will be executed before rendering html content from server side control
Control behaviour can be changed b4 producing client side control


Page Unload
This will be executed once memory is released for webpage
Closing database connection

kirangiet

  • Sep 10th, 2009
 

Following are the events occur during ASP.NET Page Life Cycle:

1)Page_PreInit
2)Page_Init
3)Page_InitComplete
4)Page_PreLoad
5)Page_Load
6)Control Events
7)Page_LoadComplete
8)Page_PreRender
9)SaveViewState
10)Page_Render
11)Page_Unload

Among above events Page_Render is the only event which is raised by page. So, we can't write code for this event.
Note:These event are not case sensitive. So we can write Page_Init as page_init in C#. Controls Events are the event raised when some action is performed on controls.

archiii24

  • Oct 15th, 2009
 

There are 8 steps
1.Page request
2.Start
3.Page initialization
4.Load
5.Validation
6.Postback event handling
7.Rendering
8.Unload

  Was this answer useful?  Yes

Actually ASP.Net  page life cycle has two different ways

1st one: When we send  a http request to the server for a particular page the request will be initially send to a aspx engine and then the aspx engine identifies the page and if the page is build with code file technique(where the design and the code are seperated ) then the page and the code ,both will be send to generate page class if it is built with Inpage technique( where the design and the code are in the same page)then the page alone will be send as the code is existing in tha page itself ,now the page will be compiled to form page class and then the page will be  processed and rendered   and then instantiated and the result will be given as a Http Response.

2nd one: If the page is requested for the second time ,now the entire process will not take place but just request will go to the aspx engine and here the request will be identified and if it knows the page was requested for the second time the request will be transfered to the page class where the page already exists and now the page will just get processed and rendered and instanstaited and the result will be give as a response.

In the 1st case the page will be sent to the server and the complete process of generating the page will take place but in the second case the page which was already generated will be processed and rendered and instantiated and then  will be sent as a response because of which the reponse of the website developed with .net pages  is always so fast.

  Was this answer useful?  Yes

All the stages of Page Life Cycle and its relevant methods used are:  

(1) Page Initialization = Page_Init
(2) View State Loading = LoadViewState
(3) PostBack data processing = LoadPostData
(4) Page Loading = Page_Load
(5) PostBack Change Notification = RaisePostDataChangedEvent
(6) PostBack Event Handling = RaisePostBackEvent
(7) Page Pre Rendering Phase = Page_PreRender
(8) View State Saving = SaveViewState
(9) Page Rendering = Page_Render
(10) Page Unloading = Page_UnLoad

  Was this answer useful?  Yes

emanmoussa

  • Jun 17th, 2010
 

These are General ASP.NET Life Cycle

1. Page Request
This happens once the user requests a page.The ASP.NET checks whether this is the first call, hence the page is to be compiled or a cached version already exists and can be sent to the user. This event occurs and triggers the start of page life cycle

2. Start
In the Start phase, some of the page properties such as Request, Response are set as well as the IsPostback property

3. Initialization
In this phase, controls on page are created; however, viewstate is not available in case the page is posted back.

4. Load
In this phase, control properties including viewstate property is available in case the page is posted back.

 
5. Postback Event Handling & Validation
In this phase, if the page is posted back, control event handlers are called and after that the Validate method of all validator controls is called setting the IsValid property of each control

6. Rendering
  Just before this stage, view state is saved for page and all controls. In this phase,  the render method is called for each control.


7.Unload

In this phase the page is discarded  and clean up is performed. Note the unload is called after the page has been fully rendered and sent to the client.



 

For more information about events that are fired during each stage, please check

the reference below


  Was this answer useful?  Yes

Abhijit

  • Apr 1st, 2015
 

I wont go in detail but I can write down the sequence of execution.
1) PreInit
2) Init
3) InitComplete
4) PreLoad
5) Load
6) Controls Event (postback events of all controls on page)
7) LoadComplete
8) PreRender
9) SaveSateComplete
10) Render
11) Unload

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions