Social Icons

Pages

Sunday, January 19, 2014

ASP.NET Application and Page Life Cycle

This is my first article on ASP.NET and I will try to explain the basics of ASP.NET and it’s life cycle.

ASP.NET is a new ASP generation. It is not compatible with Classic ASP, but ASP.NET may include Classic ASP.It is built on the Common Language Runtime (CLR), allowing programmers to write ASP.NET code using any supported .NET languages. It is a server side scripting technology that enables scripts to be executed by web server (IIS).

ASP.NET has better language support, a large set of user controls, XML-based components, and integrated user authentication.ASP.NET pages have the extension .aspx, and are normally written in VB or C#.

When a browser requests an ASP.NET file, the ASP.NET engine reads the file, compiles and executes the scripts in the file, and returns the result to the browser as plain HTML.If the request is for an HTML page, the request is fulfilled by fetching the files from the OS and then returning it to the client. If the client is requesting an ASP.NET page, IIS will pass the request to the ASP.NET runtime, which will then process the application by reads the file, line by line, and executes the scripts in the file. After process complete it returns the output to the client as pure html format.

When an ASP.NET page runs, the page goes through a life cycle in which it performs a series of processing steps.
Page Request
Start -S
Initialization - I
Load - L
Validate- V
Event Handlers - E
Render- R
Unload
In order to memorize, keep store this word "SILVER" in your memory. there's one step Before and after.

Page Request
The page request occurs before the page life cycle begins. When the page is requested by a user, ASP.NET determines whether the page needs to be parsed and compiled, or whether a cached version of the page can be sent in response without running the page.

Start
In the start stage, page properties such as Request and Response are set. At this stage, the page also determines whether the request is a postback or a new request and sets the IsPostBack property. The page also sets the UICulture property.

Initialization
During page initialization, controls on the page are available and each control's UniqueID property is set. A master page and themes are also applied to the page if applicable. If the current request is a postback, the postback data has not yet been loaded and control property values have not been restored to the values from view state.

Load
During load, if the current request is a postback, control properties are loaded with information recovered from view state and control state

Validate & Event Handling
If the request is a postback, control event handlers are called. After that, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page. There is an exception to this sequence: the handler for the event that caused validation is called after validation.

Render
Before rendering, view state is saved for the page and all controls. During the rendering stage, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream object of the page's Response property.
  
Unload
The Unload event is raised after the page has been fully rendered, sent to the client, and is ready to be discarded. At this point, page properties such as Response and Request are unloaded and cleanup is performed.

The following image shows some of the most important methods of the page class that you can override in order to add code that executes at specific points in the page life cycle.

References:
http://msdn.microsoft.com/en-us/library/ms178472.aspx

Happy New Year 2014...!!

Time for a new beginning, new days and a new year.I Hope this new year fills your life with happiness and perfect health as always, much more success and happiness...!!
I would like to express my sincere thanks to all the visitors, readers, followers of my blog for their encouragement, feed backs and support.
May this new year bring many new opportunities in your way and you can take best of it.

Many Thanks
Mathy