Solved

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

Posted on 2008-10-07
3
712 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_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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