Let us take an example ASP.NET page with the following characteristics:
- It contains a single Label control (lbl) with its “Text” property set to “statictext”
- It contains a Button control (btnA) with code in its event handler that sets the “Text” property of “lbl” to “dynamictext”
- It contains a Button control (btnB) whose purpose is to cause a page postback
Now, let us examine what will happen during the page life cycle.
- The page is first loaded
- The compiled class of the page is generated and “statictext” is assigned to “lbl.Text”
- Tracking for Viewstate is enabled in the “InitComplete” event
- “LoadViewState” is not fired because there is no postback
- “SaveViewstate” is fired, but nothing happens because no change of state is recorded
- The page is rendered with the value “statictext” inside “lbl”
- The compiled class of the page is generated and “statictext” is assigned to “lbl.Text”
- btnA is clicked
- The previously generated compiled class is handed the request; “lbl.Text” is set to “statictext”
- Tracking for Viewstate is enabled
- “LoadViewState” is fired, but nothing happens because no change of state was recorded in the previous page visit
- “RaisePostbackEvent” event is executed and “btnA” click event handler is fired; “lbl.Text” is set to “dynamictext”; since tracking is enabled at this stage, this item is tracked (marked as “Dirty”).
- “SaveViewState” is fired; “dynamictext” is serialized and stored in the __VIEWSTATE field
- The page is rendered with the value “dynamictext” inside “lbl”
- The previously generated compiled class is handed the request; “lbl.Text” is set to “statictext”
- btnB is clicked
- The previously generated compiled class is handed the request; “lbl.Text” is set to “statictext”
- Tracking for Viewstate is enabled
- “LoadViewState” is fired; since a change of state was recorded from the previous page visit, __VIEWSTATE is loaded and the value “dynamictext” is extracted; this value is then assigned to “lbl”
- “RaisePostbackEvent” event is executed; nothing happens here because “btnB” has no event handler for its “Click” event
- “SaveViewState” is fired, but nothing happens because no change of state is recorded
- The page is rendered with the value “dynamictext” inside “lbl”
- The previously generated compiled class is handed the request; “lbl.Text” is set to “statictext”
0 comments:
Post a Comment