This bit of the MSDN documentation is (mostly) wrong. As you discovered, reverse processing and validation are performed even if you dynamically add controls to the Load event.
The following are the life cycle steps for an ASP.NET page that are relevant to this issue:
- Raise the
Init event. - Postbacks: download status and download status.
- Postbacks: Download published form data (first attempt).
- Raise the
Load event. - Postbacks: Download published form data (second attempt).
- Postbacks: check the form and raise the postback event.
The documentation is correct when it says that "the added control does not catch up with the processing of the postback data." But he overlooks the fact that there are two attempts to load hosted form data, once before the Load event and once after. Thus, if you dynamically add a control to the Load event, it will be filled with the published form data at the time of the postback event (for example, submitButton_Click ).
As far as I can tell, here's the main difference and a potential trap:
- If you dynamically add a control to
Init , you can access its published form data in Load . - If you dynamically add a control to
Load , you need to wait until the postback event (or directly access the HttpRequest.Form collection).
source share