ASP.NET Page Life Cycle

ASP.NET Page Life Cycle
Techiio-author
Written by Sagar RabidasJanuary 23, 2022
8 min read
ASP .Net
1 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWS SHARE
Techiio-author
Sagar Rabidas

Software Developer

In this blog, we will discuss ASP.NET Page Life Cycle

ASP.NET Page Life Cycle

The levels of the asp.net page life cycle are initialization, instantiation of controls, restoration and renovation of the kingdom, execution of event handler codes, and page rendering. Asp.net web page lifestyles cycle is an internet software framework that becomes advanced and advertised via Microsoft to allow programmers to construct dynamic web packages. It permits customers to apply featured languages like c# or vb.net. It uses the HTTP instructions, works on a pinnacle of the HTTP protocol, and uses HTTP guidelines to set bilateral verbal exchange for browser-to-server. Asp.Net codes can be written in any of these languages: c#, j#, JScript, or visible primary.net. Asp.net has a massive wide variety of controls like text containers, buttons, and labels that may be required for manipulating and assembling the code for the advent of HTML pages.

The various stages of the ASP.NET Page Life Cycle are as below:

blogpost

PreInit

  • In this stage, the IsPostBack property is checked to find whether or not it is the first time that the page is being processed.
  • Creation or re-creation of dynamic controls.
  • Setting up the master page dynamically.
  • Setting up the Theme property dynamically.

Init

  • This stage fires up after each control has been initialized.
  • Every control’s UniqueID is set.
  • This stage is also used to initialize control properties.
  • The event is first of all fired for the bottom-most control and then fired upwards the hierarchy until the page itself.

InitComplete

  • This event can be used to make changes to the view state.
  • This event is raised by the Page object.
  • The event can be used for task processing that needs initialization to be completed.

OnPreLoad

  • This particular event is always raised after the state is displayed by page load for itself as well as all controls, as well as after it processes the postback data that has gone along with the Request instance.
  • OnPreLoad also loads view state for itself as well as all controls before the Page instance raises this particular event, and after that processes any postback data in the Request instance.

Load

  • The load method is called on the Page object, and then recursively, it does the same for each child control all controls are loaded. The Load event of the page occurs before the Load event of the individual controls.
  • It is the first place in the page lifecycle where all values are restored.
  • The value of IsPostBack is checked mostly to avoid unnecessary resetting state.
  • We can call the validate method and verify that IsValid.
  • We can also create dynamic controls here.
  • OnLoad event method is also used to establish database connections and set properties in controls.

Control PostBack Event(s)

  • NET would now call those events on the page or either its controls that had caused the PostBack to take place.
  • In this event, if the page has any of the validator controls, we need to check the IsValid property of the Page before we perform any kind of processing, and also we need to check the same property for individual validation controls.
  • It is an example of a control event such as the button click event that has caused the postback.

LoadComplete

  • This event is raised at the end of the event-handling stage.
  • LoadComplete event is used for the work that requires all remaining controls on the page to get loaded.

OnPreRender

  • OnPreRender event will be raised only after the Page object has created all required controls as well as child controls to render the page.
  • PreRender event on the Page object is raised by Page Object, and afterward, recursively, it does the same for each of the children.
  • The PreRender event of the page occurs before the PreRender event of the individual controls.
  • It also allows final changes to the page.
  • This stage occurs before saving ViewState, so changes that are made here are saved.

OnSaveStateComplete

  • This is raised after the view state as well as the control state have been saved for the page and controls.
  • ViewState has been saved for the page and all controls before this particular event occurs.
  • Any changes that are made to the page or controls at this stage would be ignored.
  • The render method is the method of the page object and its controls, and it is not an event.
  • This method generates the Dynamic Hypertext Markup Language (DHTML), client-side HTML, and also the scripts that are necessary to properly display control in the browser.

UnLoad

  • This last event is used for cleaning up.
  • Here, all of the processing has occurred, and it is now safe to dispose of any remaining objects that include Page objects as well.
  • Cleanup is performed on:
  • Instances of classes that are objects.
  • Closing of opened files.
  • Closing of database connections.
  • Unload event occurs for each control and then finally for the page.
  • During this stage, the page and its controls have been rendered, thus not making it possible to make further changes to the response stream.
  • If you call a method such as the Response. Then the page would throw an exception.

aspnet
asp
Page Life Cycle
Life Cycle
1 VIEWS 0 LIKES 0 DISLIKES SHARE
0 LIKES 0 DISLIKES 1 VIEWS SHARE
Was this blog helpful?
techiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plantechiio-price-plan
You must be Logged in to comment
Code Block
Techiio-author
Sagar Rabidas
Software Developer
Techiio-followerTechiio-followerTechiio-followerTechiio-followerTechiio-follower
+9 more
300 Blog Posts
14 Discussion Threads
Trending Technologies
15
Software91
DevOps48
Frontend Development24
Backend Development20
Server Administration17
Linux Administration28
Data Center24
Sentry24
Terraform23
Ansible83
Docker70
Penetration Testing16
Kubernetes21
NGINX20
JenkinsX17
Techiio-logo

Techiio is on the journey to build an ocean of technical knowledge, scouring the emerging stars in process and proffering them to the corporate world.

Follow us on:

Subscribe to get latest updates

You can unsubscribe anytime from getting updates from us
Developed and maintained by Wikiance
Developed and maintained by Wikiance