Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-10-07
3
Medium Priority
?
716 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 2000 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 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