Solved

what is the difference in loading objects in OnInit() method and PageLoad() in .NET 2.0 c#?

Posted on 2008-10-07
3
711 Views
Last Modified: 2013-12-17
Hello,

what would be a good way to use the two methods; onInit and PageLoad in a webpage,
can someone give me an example of those two methods used in a webpage?

if there's a good example with more methods - PreRender, SaveState -  for a webpage, all information are welcome.


thank you,
0
Comment
Question by:toshi_
3 Comments
 
LVL 18

Expert Comment

by:Priest04
ID: 22664766
you caanot access viewstate in OnInit.

Goran
0
 

Author Comment

by:toshi_
ID: 22667401

What  is the consequence of not been able to access "viewstate"?
what do viewstate contain? the response from client?

could you be more explicit please,  
as i asked, i 'd love to read a nice explanation with poors and cons,

thank you in advance.
0
 
LVL 4

Accepted Solution

by:
novynov earned 500 total points
ID: 22671981
To gain a better understanding of these events, and their order of execution in the page lifecycle, I'd recommend reading up on the asp.net page lifecycle. There are numerous articles that cover this in great detail. Here are a few:

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

http://www.codeproject.com/KB/aspnet/lifecycle.aspx

http://john-sheehan.com/blog/index.php/net-cheat-sheets/

Here are some pointers to discussions on ViewState

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

http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/truly-understanding-viewstate.aspx

How is ViewState used? Here's a very high level answer. Further study is recommended.

For controls (including pages) that utilize viewstate (by default - pretty much all), viewstate contains things like property values that must be maintained between postbacks. Remember, HTTP is stateless. ASP.NET gives the illusion of state through mechanisms such as ViewState. ViewState can include style related values (e.g. cell background color), as well as data related values (e.g gridview data, current page index, currently selected item index). As a rule, control postback data (e.g the text value of an <input type="text" />) is not maintained in ViewState. For stock controls, you generally don't need to do anything with viewstate. "Using" viewstate normally comes into play when you are creating your own user or server controls that need to maintain state between postbacks. Properly utilizing viewstate requires a thorough understanding of the page lifecycle, as ViewState is loaded, tracked, and saved at specific points in the page lifecycle.


Side note: ASP.NET 2.0 includes something new called ControlState. It functions / is used similarly to ViewState with the primary difference that it (as far as I know) cannot be turned off by a control consumer. It is used to store control state that is essential to proper control functionality. Interestingly, ControlState is stored in the same hidden __VIEWSTATE field on the rendered page. Again, this is normally only a concern to control developers.

I hope this helps.

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question