Monday, January 31, 2011

Session Vs Application variable

Session Vs Application variable

Application Variables:
Application variables are the variables which remain common for the whole application for all the users… Their value can be used across the whole application by any user… And they die only when the application stops or probably when they are killed forcibly… The ideal example for these kind of variables are site counter… We can find out how many people accessed a particular site since the time it went live via application variables and incrementing the same on ever session start.

Session Variables:
Session variables are variables which remain common for the whole application but for one particular user. They also can be used across the whole application but each user will have a copy… But they die when a particular user session ends or probably when they are killed forcibly… The ideal example for this kind of variable are user id… You might want to show "Welcome Meetu Choudhary " on every page of your site till Meetu Choudhary logs off… So in session start you set a variable to "Welcome Meetu Choudhary" and kill it on end of session…

All these events session start, session end, application start, application end are found in global.asax and that’s the reason global.asax is one for the whole ASP.Net application…

Wednesday, January 5, 2011

General Page Life-cycle Stages in ASP.Net

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 step, 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. Additionally, during the start step, the page's UICulture property is set.

Page initialization:

During page initialization, controls on the page are available and each control's UniqueID property is set. Any themes are also applied to the page. 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.

Validation:

During validation, the Validate method of all validator controls is called, which sets the IsValid property of individual validator controls and of the page.

Postback event handling:

If the request is a postback, any event handlers are called.

Rendering:

Before rendering, view state is saved for the page and all controls. During the rendering phase, the page calls the Render method for each control, providing a text writer that writes its output to the OutputStream of the page's Response property.

Unload:

Unload is called 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 any cleanup is performed.