Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

FREE 12 month online training for ASP.NET & MS Expression Studio and a Free copy of MS Expression Web with Windows Server Purchase
Page Events in ASP.Net 2.0

Author: DevASP
Download Source Code : 438_ASPNetPageEvents.zip

In this article I will try to explain you when and which page event occur in ASP.Net 2.0 and how you can get the more understandability of these events flows.

When we talk about the ASP.Net 1.0/1.1 we find total of the nine events that are:

 

  • AbortTransaction.
  • CommitTransaction
  • DataBinding
  • Dispose
  • Error
  • Init
  • Load
  • PreRender
  • Unload

 

Beside these page events ASP.Net 2.0 come with more new events that provide more help to developers in handling ASP.Net page. The flow of theses events with very brief code is discussed below:

 

Note: Here I will not discuss all these events only the main events that usually come in ASP.Net page lifecycle.

 

First of all declare a global StringBuilder variable; I use the string builder variable because I want to save my string against each event. Now start adding events on your page. First event that is called is Pre_Init event:

 

Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit

 

    sb.Append("Event PreInit is Called" & "
"
)

 

End Sub 

 

  • Now the Init event is called:

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init

 

     sb.Append("Event Init is Called" & "
"
)

 

End Sub

 

  • After the Init event InitComplete event is called:

Protected Sub Page_InitComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.InitComplete

 

        sb.Append("Event InitComplete is Called" & "
"
)

 

End Sub

 

  • When the Initialization is complete page PreLoad event is called:

Protected Sub Page_PreLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreLoad

 

    sb.Append("Event PreLoad is Called" & "
"
)

 

End Sub

 

  • When the PreLoad is complete the Page_load event is called. You will be quite fimiliar about these events:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

 

    sb.Append("Event Load is Called" & "
"
)

 

End Sub

 

  • When the page is completely loaded the LoadComplete event is called:

Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete

 

    sb.Append("Event Load is Called" & "
"
)

 

End Sub

  • After the Complete load of the page the page pre rendring event is called:

Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender

 

        sb.Append("Event PreRender is Called" & "
"
)

 

End Sub

 

  • Once the render is complete PreRenderComplete is called:

Protected Sub Page_PreRenderComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRenderComplete

 

    sb.Append("Event PreRenderComplete is Called" & "
"
)

    lblEvents.Text = sb.ToString()

 

End Sub

 

  • After the completion of all the events the Page_Unload event is called notice you will not see this event because it is called at the end of the page.

Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload

 

    sb.Append("This event is called when your page is complete rendered" & "
"
)

 

End Sub

 

You can check the flow of these events by turning on the tracing. 

Article Comments
It Is Very Nice

Posted on 8/4/2006 4:05:13 AM by sridhar

clear my doubt
about rendering,autowireup,working with stored procedure,need of tracing,

Posted on 12/28/2006 6:09:25 AM by manoj

very simple article only helpful for beginners

Posted on 2/7/2007 5:31:30 AM by hfr

The article is very clear and straight forward.

Posted on 2/16/2007 4:03:25 AM by Navpreet Singh

Really Nice. Also need some description about the concepts.
It's really helpful.

Posted on 8/8/2007 1:13:18 AM by Sridhar

This artical is good to clear all fundamental about page events but we can't learn more.

Posted on 9/14/2007 2:09:07 AM by nick

Hi,
Its good article but i think it needs some more explanation on what the event does and when excatly each event actually comes into picture.

Posted on 9/14/2007 2:29:19 AM by Harshal

dear DevASP i want master page not to flicker when i go to the content pages in asp.net plz give me the solution .it will be a great help for me sir

Posted on 9/27/2007 5:29:37 AM by jagadeesh kumar sanapala

Simple explanation is not so simple to make people understand simply.

So good job.

Posted on 10/25/2007 12:25:43 AM by Arindam Chakraborty

Its Sweet and Simple.

Posted on 12/28/2007 2:11:24 AM by Ramachandra

Yes article is very complete :D

nice

MCAD.NET, MCP

Posted on 2/15/2008 8:09:31 AM by Roger

Excellent artical for the asp.net beginners

Posted on 2/22/2008 2:24:12 AM by parmesh

This Article is very nice.This is very useful for beginner.

Posted on 3/21/2008 3:21:10 AM by Ramalakshmi.I

Nice job,

saved me a hell lot of a time

Posted on 11/16/2009 7:45:26 PM by Rick

Very Usefull for beginer

Posted on 1/5/2010 12:47:29 PM by vijay.k

U Should have Explain about the Events what they does

Posted on 5/26/2010 6:58:48 AM by Vigneshwar

very use full for freshers

Posted on 10/12/2010 2:56:12 AM by kavya

very use full for freshers

Posted on 10/12/2010 2:56:55 AM by kavya

Simple article thanks...

Posted on 11/12/2010 4:36:55 AM by indhu

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Creating a Two Level ComboBox using Java Script in ASP.Net

Disclaimer - Privacy
© 2002-2014 DevASP.net