title: Order of calling of CreateChildControls() and ApplyChanges() methods in a SharePoint web part
body: <p>I am creating a web part for SharePoint. I have a custom editor part which is overriding the SyncChanges() and ApplyChanges() methods (among others).</p>
  
  <p>The problem is that when I click OK in edit mode, the page is switched to browse mode, but data (propeties) which were changed in the EditorPart and saved in the ApplyChanges() method are not updated. I must 'enter the page' again (reload without POSTing the data again) to see the change that was made.</p>
  
  <p>I debugged it and figured out what it is doing - after clicking OK in edit mode, WebPart.CreateChildControls() is called first, and EditorPart.ApplyChanges() second. So the data was updated but being displayed was the non-updated data.</p>
  
  <p>I figured something else in this behavior: Adding one specific control to my WebPart in CreateChildControls() causes the wrong order of calling WebPart.CreateChildControls() and EditorPart.ApplyChanges(). In my case it causes adding of the WebDataTree or UltraWebTree controls (from Infragistics) but it can also happen with the common ASP.NET TextBox (as described the same problem in detail here: <a href="http://forums.asp.net/p/1157529/3308057.aspx" rel="nofollow noreferrer">ASP.net forum thread</a>).</p>
  
  <p>So if I add the tree, CreateChildControls() is called first and ApplyChanges second, so it is not actual. I must refresh to see the changes I made in the editor part.</p>
  
  <p>If I comment adding the tree to the controls collection, ApplyChanges is called first and everything is ok (except I need that tree :) )...</p>
  
  <p>Does anyone know what can cause this weird behavior?</p>