title: Adding control to ASP.NET with jQuery
body: <p>I'm trying to add control to the ASP.NET page. Controls are added successfully but can't access from code behind. In the sample below, when Button1 is clicked, there's no element in "uploads" (type HttpFileCollection).</p>
  
  <p>Here's my mark-up:</p>
  
  <pre><code>&lt;%@ Page Language="vb" AutoEventWireup="false" CodeBehind="add-remove-control.aspx.vb"
      Inherits="APIU.Web.add_remove_control" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
  
      &lt;script src="_Assets/scripts/jquery.js" type="text/javascript"&gt;&lt;/script&gt;
  
      &lt;script type="text/javascript"&gt;
          $(function() {
  
              var i = 1;
              //allow only 3 elements
  
              $('#add').click(function() {
                  if (i &lt; 4) {
                      var add_input = '&lt;input type="file" id="' + 'dynamic:' + i + '" name="' + 'dynamic:' + i + '" /&gt;'
                      var add_link = '&lt;a href="#" class="remove"&gt;Remove&lt;/a&gt;'
                      $('body').append('&lt;p&gt;' + add_input + add_link + '&lt;/p&gt;');
                      i++;
                  }
              });
  
              $('.remove').live('click', function() {
                  $(this).parent('p').remove();
                  i--;
              });
  
  
          });
      &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          &lt;a href="#" id="add"&gt;Add&lt;/a&gt;
  
          &lt;asp:Button ID="Button1" runat="server" Text="Button" /&gt;
          &lt;br /&gt;
          &lt;p&gt;
              &amp;nbsp;&lt;/p&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Code behind:</p>
  
  <pre><code>Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
          Dim uploads As HttpFileCollection
          uploads = HttpContext.Current.Request.Files
  
          Dim sfile As String
  
  
          For i As Integer = 0 To (uploads.Count - 1)
  
              If (uploads(i).ContentLength &gt; 0) Then
                  Dim c As String = System.IO.Path.GetFileName(uploads(i).FileName)
  
                  Try
                      uploads(i).SaveAs("C:\UploadedUserFiles\" + c)
  
                      sfile += uploads(i).FileName &amp; "&lt;br/&gt;"
  
                  Catch Exp As Exception
  
                  End Try
  
              End If
  
          Next i
  
  
      End Sub
  </code></pre>
  
  <p>Why there's no element in "uploads" (type HttpFileCollection)?</p>