OnPreLoad Raised after the page loads view state for itself and all controls, and after it processes postback data that is included with the Request instance.
Before the Page instance raises this event, it loads view state for itself and all controls, and then processes any postback data included with the Request instance.
Loads ViewState: ViewState data are loaded to controls. Loads Postback data: Postback data are now handed to the page controls. Load The Page object calls the OnLoad method on the Page object, and then recursively does the same for each child control until the page and all controls are loaded. The Load event of individual controls occurs after the Load event of the page.
This is the first place in the page lifecycle that all values are restored. Most code checks the value of IsPostBack to avoid unnecessarily resetting state. You may also call Validate and check the value of IsValid in this method. You can also create dynamic controls in this method. Use the OnLoad event method to set properties in controls and establish database connections. NET now calls any events on the page or its controls that caused the PostBack to occur.
Use these events to handle specific control events, such as a Button control's Click event or a TextBox control's TextChanged event. In a postback request, if the page contains validator controls, check the IsValid property of the Page and of individual validation controls before performing any processing.
This is just an example of a control event. Here it is the button click event that caused the postback. LoadComplete Raised at the end of the event-handling stage. Use this event for tasks that require that all other controls on the page be loaded. OnPreRender Raised after the Page object has created all controls that are required in order to render the page, including child controls of composite controls. The Page object raises the PreRender event on the Page object, and then recursively does the same for each child control.
The PreRender event of individual controls occurs after the PreRender event of the page. Allows final changes to the page or its control. This event takes place before saving ViewState, so any changes made here are saved. For example: After this event, you cannot change any property of a button or change any viewstate value. Use the event to make final changes to the contents of the page or its controls. OnSaveStateComplete Raised after view state and control state have been saved for the page and for all controls.
Before this event occurs, ViewState has been saved for the page and for all controls. Simply put, for controls not tracking their view state, any values added to their ViewState are lost across postbacks. All controls turn on view-state tracking immediately after raising their Init event, and the page is no exception. The overall view state of the page is a sort of call context and contains the state of each constituent control the last time the page was served to the browser.
At this stage, each control is given a chance to update its current state to make it identical to what it was on last request. If something needs be customized here, you have to resort to overriding the LoadViewState method, defined as protected and virtual on the Control class. Posted data usually takes the following form:. These values are loaded into an internal-use collection. The page processor attempts to find a match between names in the posted collection and ID of controls in the page.
Whenever a match is found, the processor checks whether the server control implements the IPostBackDataHandler interface. If it does, the methods of the interface are invoked to give the control a chance to refresh its state in light of the posted data. In particular, the page processor invokes the LoadPostData method on the interface. If the method returns true —that is, the state has been updated—the control is added to a separate collection to receive further attention later.
As mentioned, during the processing of posted data, posted names are matched against the ID of controls in the page. Which ID? Posted names are matched against the unique ID of page controls. Client IDs are irrelevant in this instance because they are not posted back to the server. The PreLoad event merely indicates that the page has terminated the system-level initialization phase and is going to enter the phase that gives user code in the page a chance to further configure the page for execution and rendering.
This event is raised only for pages. The Load event is raised for the page first and then recursively for all child controls. At this time, controls in the page tree are created and their state fully reflects both the previous state and any data posted from the client. The page is ready to execute any initialization code related to the logic and behavior of the page.
At this time, access to control properties and view state is absolutely safe. This apparently weird approach addresses a specific scenario—the use of dynamically created controls. Imagine adding a control to the page tree dynamically—for example, in response to a certain user action.
As mentioned, the page is rebuilt from scratch after each postback, so any information about the dynamically created control is lost. However, the ASP. NET framework recognizes that some controls could be created in the Load event. For this reason, it makes sense to give it a second try to see whether a match is possible after the user code has run for a while.
If the dynamic control has been re-created in the Load event, a match is now possible and the control can refresh its state with posted data. The postback mechanism is the heart of ASP. NET programming. It consists of posting form data to the same page using the view state to restore the call context—that is, the same state of controls existing when the posting page was last generated on the server.
There are two main types of events. The first type of event signals that certain controls had the state changed over the postback. The second type of event executes server code in response to the client action that caused the post.
The whole ASP. NET machinery works around an implicit assumption: there must be a one-to-one correspondence between some HTML input tags that operate in the browser and some other ASP. NET controls that live and thrive in the Web server. To be more technically precise, the link is given by a common ID name. When the user types some new text into an input element and then posts it, the corresponding TextBox control—that is, a server control with the same ID as the input tag—is called to handle the posted value.
The method signals the control to notify the ASP. NET application that the state of the control has changed. The implementation of the method is up to each control. Connect and share knowledge within a single location that is structured and easy to search. It's loaded into memory between init and load.
See t his article for a full break down of the page lifecycle. After reading it I designed a graphic that helped me to understand better what was happening on between each stage and when and how ViewState was doing its job. I'd like to share this graphic with other people that like myself need to see how stuff work in a more visual way. Hope it helps! Click on the image to view at full width. You can see from the page life cycle as explained on MSDN.
That the view state is loaded during the Load phase of the page lifecycle, i. The viewstate is actually loaded between initComplete and Preload events. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.
Learn more. In ASP. Net, during which page lifecycle event does viewstate get loaded? Ask Question.
0コメント