Reputation: 4219
I was asked to explain the ASP.NET page life cycle in an interview some time back. I did explain it to him, but he was not satisfied with my answer. Could someone explain the life cycle to me please?
Upvotes: 37
Views: 107382
Reputation: 28666
There are 10 events in ASP.NET page life cycle, and the sequence is:
Below is a pictorial view of ASP.NET Page life cycle with what kind of code is expected in that event. I suggest you read this article I wrote on the ASP.NET Page life cycle, which explains each of the 10 events in detail and when to use them.
Image source: my own article at https://www.c-sharpcorner.com/uploadfile/shivprasadk/Asp-Net-application-and-page-life-cycle/ from 19 April 2010
Upvotes: 16
Reputation: 47
This acronym might help you to remember the ASP.NET life cycle stages which I wrote about in the below blog post.
R-SIL-VP-RU
- Request
- Start
- Initialization
- Load
- Validation
- Post back handling
- Rendering
- Unload
From my blog: Understand ASP.NET Page life cycle and remember stages in easy way
18 May 2014
Upvotes: 0
Reputation: 797
Partial Class _Default
Inherits System.Web.UI.Page
Dim str As String
Protected Sub Page_Disposed(sender As Object, e As System.EventArgs) Handles Me.Disposed
str += "PAGE DISPOSED" & "<br />"
End Sub
Protected Sub Page_Error(sender As Object, e As System.EventArgs) Handles Me.Error
str += "PAGE ERROR " & "<br />"
End Sub
Protected Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init
str += "PAGE INIT " & "<br />"
End Sub
Protected Sub Page_InitComplete(sender As Object, e As System.EventArgs) Handles Me.InitComplete
str += "INIT Complte " & "<br />"
End Sub
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
str += "PAGE LOAD " & "<br />"
End Sub
Protected Sub Page_LoadComplete(sender As Object, e As System.EventArgs) Handles Me.LoadComplete
str += "PAGE LOAD Complete " & "<br />"
End Sub
Protected Sub Page_PreInit(sender As Object, e As System.EventArgs) Handles Me.PreInit
str = ""
str += "PAGE PRE INIT" & "<br />"
End Sub
Protected Sub Page_PreLoad(sender As Object, e As System.EventArgs) Handles Me.PreLoad
str += "PAGE PRE LOAD " & "<br />"
End Sub
Protected Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
str += "PAGE PRE RENDER " & "<br />"
End Sub
Protected Sub Page_PreRenderComplete(sender As Object, e As System.EventArgs) Handles Me.PreRenderComplete
str += "PAGE PRE RENDER COMPLETE " & "<br />"
End Sub
Protected Sub Page_SaveStateComplete(sender As Object, e As System.EventArgs) Handles Me.SaveStateComplete
str += "PAGE SAVE STATE COMPLTE " & "<br />"
lbl.Text = str
End Sub
Protected Sub Page_Unload(sender As Object, e As System.EventArgs) Handles Me.Unload
'Response.Write("PAGE UN LOAD\n")
End Sub
End Class
Upvotes: -2