ASP.NET Dynamic controls created in Page_Pre_init () or Page_Init () or Page_Load ()

Where is the best place to create dynamic controls in ASP.NET? MSDN says Pre_init, another MSDN Init article, and some people say that the Load event (which I read is not good to do).

I am studying MS certification and I want to make sure that I know which one is perfect and why. My initial thought was to create an object in pre_init and assign any property values ​​in the Load event (so that the ViewState is loaded for the dynamic control).

+5
source share
2 answers

I recommend page_Init (). This will circumvent the ViewState problem, which will not load sequentially. The controls will be available, but the viewstate is not yet applied to them. This is exactly where you want to add controls to the second article.

Also, based on experience, this is what works. any other approach still caused me problems.

+4
source

It depends, but I think the general consensus is better than before. Therefore, if you add dynamic controls to the page, add them to the Pre_Init phase if you can. If you add user controls to a user control, add them to the Init phase if you can (the controls do not have Pre_Init).

, .

  • (, ).
  • , , . , , , , .

, , .

+4

All Articles