I agree with @Joel, knowing the life cycle of the page, the nature of statelessness, etc., you can avoid traps. The main thing to pay attention to, what I had to do is:
Page_Init - initialize the controls that are on the page here, since they were the last time you displayed the page. This is important because the ViewState starts after Init and requires the same controls to be initialized the same as the previous ones. You can load the control using the code from @Mitchel ie
Control ControlInstance = LoadControl ("MyControl.ascx"); myPlaceholder.Controls.Add (ControlInstance);
Page_Load. Download the contents of the controls here, as with any control that does not load dynamically. If you saved a link to them in your page_init, they will be available here.
Saving this structure I had too many difficulties, because it is similar to how ASP.NET was designed to work, even if all the samples in MSDN do not do it this way. The most important thing you need to observe is to keep track of the state of the page in relation to the controls you have provided.
In my case, he took the section number of the multi-page survey and reloaded the questions from the database, so all I had to do was keep track of the current section number, which was not complicated.
Having said all this, if you use dynamic controls to show and hide different views of the same screen, I suggest you not to use them. In this case, I would rather use either user controls (with inappropriate hidden ones) or placeholders to mark areas that have not yet been displayed, or individual pages / views, etc. So that you save pages to one responsibility, which makes it easier to debug and / or get useful information from the user about which page they were on.
source share