Solved

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

Posted on 2008-10-07
3
713 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

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

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

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

696 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