Solved

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

Posted on 2008-10-07
3
702 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
Comment Utility
you caanot access viewstate in OnInit.

Goran
0
 

Author Comment

by:toshi_
Comment Utility

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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now