ASP.NET Page life cycle and ViewState

8,146 views

Published on

This session is a brief on the pre page life cycle events(Just a quick route map), the Page life cycle events, how is Viewstate important to page life cycle events & Life without Viewstate.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
8,146
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
202
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

ASP.NET Page life cycle and ViewState

  1. 1. Page Life Cycle And ViewState Presenter: Vijay Goyal, Mindfire Solutions Skype: mfsi_vijayg Date: 30/09/2013
  2. 2. Agenda Of The Seminar - Pre Page Life Cyle (Asp.Net Inside IIS) What on Earth is ViewState? The different (Important) stages of Life Cycle Where ViewState comes into the picture? Dynamically created control Deal with the burden of ViewState on the page Some Demo...with some more Demo Conferrer: Vijay Goyal, Mindfire Solutions
  3. 3. This is not an IIS course Conferrer: Vijay Goyal, Mindfire Solutions
  4. 4. The Two Important Services Conferrer: Vijay Goyal, Mindfire Solutions
  5. 5. The ProcessRequest() - After all the registered Modules are executed. The page is ready to be served. - For this IIS uses the handler's mapping, to map the request to the appropriate handler. - ProcessRequest() method is executed and Page Life Cycle begins Conferrer: Vijay Goyal, Mindfire Solutions.
  6. 6. The Page Life Cycle Begins.. Conferrer: Vijay Goyal, Mindfire Solutions
  7. 7. Formation Of Control Heirarchy - Request to an aspx page is served by a compiled class “C:WindowsMicrosoft.NETFrameworkv4.0.30319Temp orary ASP.NET Files” - Initializes the page's control hierarchy Conferrer: Vijay Goyal, Mindfire Solutions
  8. 8. Formation Of Control Heirarchy Conferrer: Vijay Goyal, Mindfire Solutions
  9. 9. But What's ViewState?? - Its a misunderstood topic An object of Statebag class Stores changes done programatically SelectedIndex / PageIndex not stored A property of System.Web.UI.Controls A key/value pair indexer. Serialized to _VIEWSTATE hidden field ViewState is a hungry beast. Conferrer: Vijay Goyal, Mindfire Solutions
  10. 10. Initialization - PreInit (Entry point, Non Recursive) - Init (Tracking of Viewstate is not enabled / Enabled for child controls, Recursive) - InitComplete (Viewstate tracking is turned on, Non Recursive) - SaveViewState() - Page.TrackViewState() Conferrer: Vijay Goyal, Mindfire Solutions.
  11. 11. Load ViewState/Page Data - Invoked only on Postbacks - LoadControlState (Introduced in Asp.Net 2.0, gridview page control, SaveControlState()l) - LoadViewState SaveViewState()) - LoadPostData (Page and controls restored, (Controls implement IpostBackDataHandler, Selected value in dropdown, checkbox, Textbox) Conferrer: Vijay Goyal, Mindfire Solutions.
  12. 12. Loading the Page... - PreLoad (Non Recursive, End of Viewstate data load) - Load (Top down approach, Previous State is fully loaded) - RaisePostDataChangeEvent (Controls implement IpostBackDataHandler, TextChanged/SelectedIndexChanged) - RaisePostBackEvent click event) - LoadComplete (Controls implement IpostBackDataHandler, (Page only) Conferrer: Vijay Goyal, Mindfire Solutions
  13. 13. Page Rendering - PreRender (Recursive, Last update before the page is rendered) - PreRenderComplete view state is saved.) (last event before the page's - SaveControlState - SaveViewState (Control/Viewstate data are serialized to _VIEWSTATE) - Render and Unload (Renders the html to Client, Final Cleanup,closing db, finishing up logging..etc) Conferrer: Vijay Goyal, Mindfire Solutions
  14. 14. A Scenario Conferrer: Vijay Goyal, Mindfire Solutions
  15. 15. Dynamically Added Controls - They are not part of the compiled class - Should be added in every page execution - Plays catchup (go thru all the page life cycle events of their own, Before Page Render) - Recommended to call in PreInit or Init, before tracking is enabled Conferrer: Vijay Goyal, Mindfire Solutions
  16. 16. Abbreviating ViewState - Disable ViewState - System.Web.UI.LosFormatter (Limited Object Serialization) - Compress/Decompress (SavePageStateToPersistenceMedium, LoadPageStateFromPersistenceMedium) - Store in an external file (Use SessionId/ GUID) - Others... (Flesk.ViewStateOptimizer) Conferrer: Vijay Goyal, Mindfire Solutions
  17. 17. Security?? - ViewState Decoder (a nice tool created by Fritz Onion). - EnableViewStateMac - ViewStateEncryptionMode (Always/Auto , control calls Page.RegisterRequiresViewStateEncryption() /Never) Conferrer: Vijay Goyal, Mindfire Solutions
  18. 18. Prevent Tampering Conferrer: Vijay Goyal, Mindfire Solutions
  19. 19. Prevent Tampering Conferrer: Vijay Goyal, Mindfire Solutions
  20. 20. Here and there... Machine.Config file <machineKey validation="SHA1" validationKey="F3690E7A3143C185AB1089616A8B4D81FD55DD7A69EEAA3B32A6AE 813ECEECD28DEA66A23BEE42193729BD48595EBAFE2C2E765BE77E006330BC3B139 2D7C73F" DecryptionKey =” ” /> - Local Security Authority Subsystem Service component - References http://msdn.microsoft.com/en-us/library/ff649308.aspx http://msdn.microsoft.com/en-us/library/ms178472.aspx http://pluralsight.com Conferrer: Vijay Goyal, Mindfire Solutions
  21. 21. Conferrer: Vijay Goyal, Mindfire Solutions
  22. 22. Presenter: Vijay Goyal, Mindfire Solutions

×