title: Why can ASP.NET Dynamic controls keep the ViewState even when added in Page_Load?
body: <p>I have done a bit of research related to dynamic controls and ViewState.</p>
  
  <p>And I read that in order to keep the ViewState for a dynamic control you have to add it in the  Page_Init event. It makes sense because the  PageLifeCycle is :</p>
  
  <ol>
  <li>Initialization.</li>
  <li>LoadViewState.</li>
  <li>LoadPostbackData.</li>
  <li>Load.</li>
  <li>RaisePostbackEvent.</li>
  <li>SaveViewState.</li>
  <li>Render.</li>
  </ol>
  
  <p>But I made a test app and I saw that the ViewState and properties values are preserved even if I add the control in the Page_Load event and not after. From this on I only found contradictory informaton. Some say that the controls may catch up the PageLifeCycle other say you must add them in the Page_Init. Can someone clarify this for me?</p>
  
  <p>Also in msdn I found:</p>
  
  <blockquote>
    <p>Note   You may be able to get away with loading your controls in the
    Page_Load event handler and maintaining the view state properly. It
    all depends on whether or not you are setting any properties of the
    dynamically loaded controls programmatically and, if so, when you're
    doing it relative to the Controls.Add(dynamicControl) line. A thorough
    discussion of this is a bit beyond the scope of this article, but the
    reason it may work is because the Controls property's Add() method
    recursively loads the parent's view state into its children, even
    though the load view state stage has passed.</p>
  </blockquote>
  
  <p>But I don't really understand this fully so I hope someone can explain it. Thank you in advance.</p>