Thursday, 12 April 2018

003 LIFE CYCLE

An Asp.Net page has two part , C# and aspx file. When in ASP.NET page process , there are several steps in it. ASP.NET life cycles  includes.
  • Page process, dynamic output is generated.
  • Page class and application class are compiled dynamically.
  • Application and classes instance is created dynamically

Asp.net page life cycle has two part

  • Application life cycle
  • Page life cycle

Application lifecycle

  • An user  request to IIS  server  through browser.IIS fast check,  the extension that can be process by the IIS. If page is .aspx  extension , then it is pass by 'aspnet_isapi.dll' for next step of processing.Asp.Net can handled the type of file , that the extension has mapped to it.Asp.Net IIS can handle .aspx,ashx,.asmx file extension by default.

  • An ApplicatioManager class is created , to run application smoothly .The purpose of application manager to create a separate domain to separate application global variable from other application, running  in the same IIS server.

  • Now the new domain has created for the application, next need the hosting environment . HostingEnvironment  class is created to provide runtime requirement resources. It is called 'http runtime'.HostingEnvironment provide infomation about the files and folder ect. Response object like HttpContext, HttpRequest, and HttpResponse is iniialised .
  • After initialisation ,HttpApplication class instance is created.Global.asax file instance is created.
  • After HttpApplicationinstance creation , configured modules are created.processing work like validation of request ,URL Mapping is done.


ASP.Net page life cycle event


PreInit :  It uses
IsPostBack property to determine the pages is created first time or need to recreate again. Dynamic controller can be created. Master page can be set, theme can be set.SkinId can be set.


protected void Page_PreInit(object sender, EventArgs e)
{
         if (this.Page.IsPostBack)
        {
           //do some logic
        }

        this.MasterPageFile = "~/MywMaster.master";
        this.Page.Theme = "MyTheme";
        this.myControl.SkinID = "MyControlSkin";
}

Init: It fire when all control are initialized,
in  the stage , each control have a unique ID. Control property also initialized.skin settings have been applied.






protected void Page_Init(object sender, EventArgs e)

{


}

Init complete: Make sure that all control
initialization process completed.
 
protected void Page_InitComplete(object sender, EventArgs e)

{

}

Preload: Load ViewState to each control ,
load postback data to each control.
Page instance is created.



protected override void OnPreLoad(EventArgs e)

{


}

load: Dynamic control can be created.Database connection can be created.
IsPostBack property check the page is new or recreated.
Make all validation of controls ,isValid works .
This is the fast method of a page , after the page is loaded.




protected void Page_Load(object sender, EventArgs e)

 



}

LoadComplete: All control has been loaded ,ViewState ,ControlState
loaded.Load method already called.This method actually complete
Load method.





protected void Page_LoadComplete(object sender, EventArgs e)

{



}

OnPreRender: After all control created and ready to render in the page. Property cannot be changed. Data binding completed with the data source.Final stage of page load.




protected override void OnPreRender(EventArgs e)

{



}

UnLoad:cleanup the page instance.
Close all connections, close all files, instance of a class is dispose.





protected void Page_UnLoad(object sender, EventArgs e)

{



}


         Asp.Net pages  created in server memory , then it is sent to Browser an server release memory. This process , page initialisation, initialisation of control, restore control property and viewstate, control state maintain is done .


            There are lot of event  in between , that need to be handle each steps. There are several inbuilt events of ASP.Net ,  this event can we override to a custom event.

Page request:
IsPostBack property is used to trace either the page has newly created on existing page, it also be decided that the page can be retrieved from server cache memory or create newly.

Starting of page life cycle: A page life cycle start with request from user to the server through browser. Server response request. Ispostback property is used to trace the page  is newly created or making round trip from server. Master page  and UI culture is set from this page.


No comments:

Post a Comment

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...