title: FileUpload and UpdatePanel: ScriptManager.RegisterPostBackControl works the second time
body: <p>I'm developing an ASP.NET application with C# and Visual Studio 2008 SP1. I'm using WebForms.</p>
  
  <p>I have an ASPX page with two UpdatePanels, one on the left that holds a TreeView and other on the right where I load dynamically user controls.</p>
  
  <p>One user control, that I used on right panel, has a FileUpload control and a button to save that file on server. The ascx code to save control is:</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="UpdatePanelBotons" runat="server" RenderMode="Inline" 
      UpdateMode="Conditional"&gt;
  &lt;ContentTemplate&gt;
      &lt;asp:Button ID="Save" runat="server" Text="Guardar" 
                  onclick="Save_Click" CssClass="button" /&gt;
      &lt;/ContentTemplate&gt;
      &lt;Triggers&gt;
          &lt;asp:PostBackTrigger ControlID="Save" /&gt;
      &lt;/Triggers&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>I make a full postback to upload the file to the server and save it to database. But I always getting False on FileUpload.HasFile.</p>
  
  <p>I problem is the right UpdatePanel. I need it to load dynamically the user controls. This panel has three UpdatePanels to load the three user controls that I use.</p>
  
  <p>Maybe I can use an Async File Uploader or delete the right Update Panel and do a full postback to load controls dynamically.</p>
  
  <p>Any advice?<BR />
  <strong>UPDATE:</strong></p>
  
  <p><code>RegisterPostBackControl</code> <strong>works</strong>... the second time I click on save button. First time FileUpload.HasFile is FALSE, and second time is TRUE.</p>
  
  <p><strong>Second Update</strong><br />
  On first click I also check ScriptManager.IsInAsyncPostBack and is FALSE. I don't understand ANYTHING!!</p>
  
  <p>Why?</p>
  
  <p>The code to load user control first time, and on each postback is:</p>
  
  <pre><code>DynamicControls.CreateDestination ud =
              this.LoadControl(ucUrl) as DynamicControls.CreateDestination;
  if (ud != null)
  {
      Button save = ud.FindControl("Save") as Button;
      if (save != null) 
          ScriptManager1.RegisterPostBackControl(save);
      PanelDestination.Controls.Add(ud);
  }
  </code></pre>
  
  <p>Thank you.</p>