ASP.NET : Page Life Cycle

Page Life Cycle
ASP.NET is a dynamic webpage that following sequential process steps include initialization, instantiating controls, restoring and maintaining state, running event handler code, and rendering. ASP.NET allowed you to write code at the appropriate Page Life Cycle stage for the effect you intend.

Figure 1: ASP.NET Page Life Cycle

See full step process here >> http://i.msdn.microsoft.com/dynimg/IC386473.png

Page Events
To manage your Page Life Cycle state, You should know some basic event first.
-  Page_Init() is the first occurs when an ASP.NET page is execute.
-  Page_Load() will occurs when all the objects on the page have been created and are available for use. 
-  Page_Unload() will occurs after everything else happens.

Post Back Events
Post Back event will occur only when a page is processed as a postback (When you click a button or something that send a data to server, postback will active and response a webpage to client again). You can check an postback with "if(Page.IsPostBack)" then it will return "true" if the page is being loaded in response to a client postback. Otherwise, if you just visit the page, a postback data is unknown or empry and it will return "false".

Example Postback (Code Behind Page)
Create a ASP.NET webpage and add one standard button for call postback.

protected void Page_Load(object sender, EventArgs e) {
   if (Page.IsPostBack)
      Response.Write("This is postback !!");
   else
      Response.Write("This is first time visit !!");
}

Figure 2: Example Result

##############################

Web Server Control << Previous Chapter || Next Chapter >> Validation Control

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...