|
You are talking about the life cycle of the control
------------------------------------------
A series of processing steps are performed during the life cycle, including:
Instantiate
A control is instantiated by a page or another control by calling its constructor. The stages listed after this step will only occur if the control is added to the control tree.
Initialize
Initialize the settings required during the life cycle of the incoming web request. At this stage, the page and all controls in the control tree call the OnInit method by default. Developers can provide initialization logic for controls by overloading the OnInit method. At this point in its lifecycle, the control can safely access its child controls placed in the Controls collection, but it cannot access parent controls in the control hierarchy or other higher-level controls (such as pages).
Begin Tracking View State
This phase occurs at the end of the initialization phase. The page automatically calls the TrackViewState method at this stage. The TrackViewState method guarantees that after this stage, changes made using the ViewState dictionary property are stored in the view state of the control. In most cases, the implementation of the TrackViewState method provided by the Control base class is sufficient. The TrackViewState method must be overridden only if the control defines complex properties.
Load View State (postback only)
This phase occurs during postback, not during the initial request. At the end of this phase, the ViewState property of the control is automatically populated. The control can override the default implementation of the LoadViewState method to restore it with a custom state.
Load Postback Data (only used for postback process, optional) (Load Postback Data (postback only, optional))
This phase only occurs in the postback when the control participates in the postback data processing by implementing the IPostBackDataHandler interface. The TextBox control is an example. At this stage, the control must update its state from the sent form data by implementing the LoadPostData method of the IPostBackDataHandler excuse.
Load
Until the beginning of this phase, all controls in the control tree have been initialized and restored to their last state in the previous cycle. The OnLoad method performs operations common to all requests, such as setting up a database query. At this point, the server controls in the tree have been created and initialized, the state has been restored, and the form controls reflect client data. If you need to implement logic that is only executed in the initial request of the page, you should check the IsPostBack property of the page when implementing this logic
Raise change events (only for the postback process, optional) (Raise Changed Events (postback only, optional))
This phase only occurs in the postback when the control participates in the postback data processing by implementing the IPostBackDataHandler interface. At this stage, the control uses a signal (such as the TextBox's TextChanged event) as a signal-its state changes due to a postback (a change event is raised in response to a state change between the current and previous postbacks). In order to participate in this phase, the control must implement the RaisePostDataChangedEvent method of the IPostBackDataHandler interface.
Raise Postback Events (Raise Postback Events (postback only, optional))
This phase occurs in the postback only when the control participates in the postback data processing by implementing the IPostBackEventHandler interface. At this stage, you can implement the logic by implementing the RaisePostBackEvent method of the IPostBackEventHandler interface in order to map client events to server events.
PreRender
At this stage, you should perform any work required before the control is generated by overloading the OnPreRender method. Performing any update before generating output saves changes made to the state of the control during the pre-build phase, and changes made during the build phase are lost.
Save View State
If the control does not maintain state, or it uses the ViewState dictionary to hold all of its state information, then there is no need to implement any additional logic during this phase. During this phase, the page framework automatically saves the ViewState dictionary. If you need custom state management, you must override the SaveViewState method to implement custom state recovery. This method is only called by controls whose EnableViewState property is true. Changes made to any control after this stage will not be saved in the view state of the control.
Generate
With this method, the control writes markup text on the output stream by overloading one of the Control's Render method or the WebControl class's rendering method.
Unload
At this stage, the page performs the cleanup by implementing the Page_Unload method. As a control developer, you should override the Dispose method to perform cleanup.
Dispose
At this stage, you should override the Dispose method to release all the resources occupied by the control. |
|