When compiling ASP. NET controls, be sure to pay attention to the control lifecycle, especially when the execution period of createchildcontrols () method is uncertain. If you are not careful, an error will occur! To sum up, pay attention to the following points:
- The generation time of the Child control is unknown. In other words, the createchildcontrols () method of the Child control is called only when the child control needs to be created.
For example, when an event is triggered, you need to know the sub-Control ID so that the event can be sent down. In this case, you need to create a sub-control.
- If the databind () method is overloaded, the entire child Control tree should be regenerated in this method. Note that all child control trees should be regenerated here. If the control displays an exception when it is submitted, check whether all child control trees are regenerated in databind.
This is because the generation time of the sub-control is unknown. If some of the sub-controls are not generated, re-generate them all to avoid this confusion. (Chaos generally occurs when data is not bound)
- In the overload render () method, data-independent and operation-independent controls are generally rendered, such as adding style forms and setting display formats.
- Tip: View status is generally used for controls that need to bind data. This control must overload the databind () method, while the databind () method regenerates the entire control tree and loads data. Therefore, you can generate as few child controls as possible in the createchildcontrols () method of this control, and only create the controls required for event triggering. (Note that to ensure the consistency of the control clientid, all controls with clientid must be created !)
I wrote this. This time is very busy and I will discuss it later when I have time.