asp.net control life cycle

 asp.net control life cycle  

Performing a series of processing steps in the life cycle, the steps comprising:

• instantiation (Instantiate)

control is another control page or by calling its constructor instantiated. After this stage the listed steps, only when the control is added to the control tree will occur.

• Initialize (Initialize)

Initialization incoming Web requests required for the life cycle of settings. At this stage, control tree of the page and all controls to invoke OnInit method by default. Developers can by overriding OnInit method to provide initialization logic for the control. At this point in its life cycle, the controls can be placed securely access their child controls Controls collection, but it can not access parent control in the control hierarchy of controls or other higher level (such as pages)



• began tracking view state ( Begin Tracking View State)

this phase occurs at the end of the initialization phase. At this stage, the page automatically call TrackViewState method. TrackViewState method ensures that after this stage, using ViewState dictionary stored property change is generated in the control view state. In most cases, TrackViewState method Control base class implementation is sufficient, and only when the control defines a complex property, it must override TrackViewState method.



• Load view state (only for return procedure) (Load View State (postback only ))

This phase occurs when the return, rather than the initial request process, at the end of this phase, it will automatically populate the control's ViewState property LoadViewState control can override the default implementation of the method, in order to restore the custom status.



• Load return data (only for the return process, is optional) (Load Postback Data (postback only , optional))

Only by implementing the controls IPostBackDataHandler interfaces involved in the return of data processing, at this stage only take place in the backhaul. TextBox control is an example. At this stage, the control must update its status LoadPostData way to achieve IPostBackDataHandler excuse from the form data is sent.



• Load (Load)

until the beginning of this phase, all the controls in the control tree have been initialized and restored to their last state in the previous cycle. OnLoad method performs the requested operation common to all, such as setting a database query. At this time, the tree of server controls have been created and initialized, the state has been restored and form controls reflect client data. If you need to implement logic executed only in the initial page request, then implement the logic, you should check IsPostBack property pages



• Modify trigger event (only for the return process, is optional) (Raise Changed Events (postback only , optional ))

only by implementing controls IPostBackDataHandler interfaces involved in the postback data processing, this stage only take place in the backhaul. In this stage, as a control signal ----- its state is changed due to the return (trigger event in response to a state change between the current and previous postback change) caused by events (such as a TextBox TextChanged event). In order to participate in this phase, the control must RaisePostDataChangedEvent method IPostBackDataHandler implementation of the interface.



• backhaul triggered event (only for the return process, is optional) (Raise Postback Events (postback only , optional))

Only by implementing the controls IPostBackEventHandler interfaces involved in the return of data processing, at this stage only take place in the backhaul. At this stage may be implemented by a logic implemented method RaisePostBackEvent IPostBackEventHandler interface, in order to map client events to server-side event.



• pre-generated (PreRender)

at this stage, it should be by overriding OnPreRender method, before performing any work needed to build the control. Perform any updates before generating the output can be saved in the pre-generation stage changes to the control state, and in the generation stage corresponding changes will be lost.



• view state is saved (Save View State)

if the control does not maintain state, or save it to use all its state information ViewState dictionary, you do not need to implement any additional logic during this phase. During this stage, the page framework will automatically save ViewState dictionary. If you need a custom state management, must implement a custom state restoration, this method is only EnableViewState property is true of the control invoked by overriding SaveViewState method. After this stage to change any of the controls are not saved in view state control.



• generating (Render)

By this method, the control on the output stream by means of a method Render Control Overload class or WebControl rendering method to write text mark.



• unloading (Unload)

at this stage, the page Page_Unload by implementing methods to perform cleanup work. As controls developer, you should override the Dispose method to perform cleanup.



• release (Dispose)

at this stage, should override the Dispose method to release all the resources occupied by the control.

Reproduced in: https: //www.cnblogs.com/liuzhaoyangg/archive/2012/09/08/2676726.html

 asp.net control life cycle  

Performing a series of processing steps in the life cycle, the steps comprising:

• instantiation (Instantiate)

control is another control page or by calling its constructor instantiated. After this stage the listed steps, only when the control is added to the control tree will occur.

• Initialize (Initialize)

Initialization incoming Web requests required for the life cycle of settings. At this stage, control tree of the page and all controls to invoke OnInit method by default. Developers can by overriding OnInit method to provide initialization logic for the control. At this point in its life cycle, the controls can be placed securely access their child controls Controls collection, but it can not access parent control in the control hierarchy of controls or other higher level (such as pages)



• began tracking view state ( Begin Tracking View State)

this phase occurs at the end of the initialization phase. At this stage, the page automatically call TrackViewState method. TrackViewState method ensures that after this stage, using ViewState dictionary stored property change is generated in the control view state. In most cases, TrackViewState method Control base class implementation is sufficient, and only when the control defines a complex property, it must override TrackViewState method.



• Load view state (only for return procedure) (Load View State (postback only ))

This phase occurs when the return, rather than the initial request process, at the end of this phase, it will automatically populate the control's ViewState property LoadViewState control can override the default implementation of the method, in order to restore the custom status.



• Load return data (only for the return process, is optional) (Load Postback Data (postback only , optional))

Only by implementing the controls IPostBackDataHandler interfaces involved in the return of data processing, at this stage only take place in the backhaul. TextBox control is an example. At this stage, the control must update its status LoadPostData way to achieve IPostBackDataHandler excuse from the form data is sent.



• Load (Load)

until the beginning of this phase, all the controls in the control tree have been initialized and restored to their last state in the previous cycle. OnLoad method performs the requested operation common to all, such as setting a database query. At this time, the tree of server controls have been created and initialized, the state has been restored and form controls reflect client data. If you need to implement logic executed only in the initial page request, then implement the logic, you should check IsPostBack property pages



• Modify trigger event (only for the return process, is optional) (Raise Changed Events (postback only , optional ))

only by implementing controls IPostBackDataHandler interfaces involved in the postback data processing, this stage only take place in the backhaul. In this stage, as a control signal ----- its state is changed due to the return (trigger event in response to a state change between the current and previous postback change) caused by events (such as a TextBox TextChanged event). In order to participate in this phase, the control must RaisePostDataChangedEvent method IPostBackDataHandler implementation of the interface.



• backhaul triggered event (only for the return process, is optional) (Raise Postback Events (postback only , optional))

Only by implementing the controls IPostBackEventHandler interfaces involved in the return of data processing, at this stage only take place in the backhaul. At this stage may be implemented by a logic implemented method RaisePostBackEvent IPostBackEventHandler interface, in order to map client events to server-side event.



• pre-generated (PreRender)

at this stage, it should be by overriding OnPreRender method, before performing any work needed to build the control. Perform any updates before generating the output can be saved in the pre-generation stage changes to the control state, and in the generation stage corresponding changes will be lost.



• view state is saved (Save View State)

if the control does not maintain state, or save it to use all its state information ViewState dictionary, you do not need to implement any additional logic during this phase. During this stage, the page framework will automatically save ViewState dictionary. If you need a custom state management, must implement a custom state restoration, this method is only EnableViewState property is true of the control invoked by overriding SaveViewState method. After this stage to change any of the controls are not saved in view state control.



• generating (Render)

By this method, the control on the output stream by means of a method Render Control Overload class or WebControl rendering method to write text mark.



• unloading (Unload)

at this stage, the page Page_Unload by implementing methods to perform cleanup work. As controls developer, you should override the Dispose method to perform cleanup.



• release (Dispose)

at this stage, should override the Dispose method to release all the resources occupied by the control.

Guess you like

Origin blog.csdn.net/weixin_34210740/article/details/93543709