title: Upload file directly after browsing it
body: <p>I have created a simple method that upload files to server when button is clicked. This method is working perfectly on button click, but I need to make it an automatic upload directly when user chooses file from his computer. Any idea about how can I make it? 
  This is my asp code:</p>
  
  <pre><code>&lt;asp:UpdatePanel ID="UpdatePanel1" runat="server"&gt;
      &lt;ContentTemplate &gt;
         &lt;asp:FileUpload ID="FileUpload1" runat="server" /&gt;
         &lt;br/&gt;
         &lt;asp:Label ID="Label1" runat="server"&gt;&lt;/asp:Label&gt;
         &lt;br/&gt;
         &lt;asp:Button ID="Button1" runat="server" Text="Upload" /&gt;
      &lt;/ContentTemplate&gt;
      &lt;Triggers&gt;
         &lt;asp:PostBackTrigger ControlID="Button1" /&gt;
      &lt;/Triggers&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>Below is the code behind:</p>
  
  <pre><code>Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
          Dim path As String = Server.MapPath("~/UploadedImages/")
          Dim fileOK As Boolean = False
          If FileUpload1.HasFile Then
              Dim fileExtension As String
              fileExtension = System.IO.Path. _
                  GetExtension(FileUpload1.FileName).ToLower()
              Dim allowedExtensions As String() = _
                  {".jpg", ".jpeg", ".png", ".gif"}
              For i As Integer = 0 To allowedExtensions.Length - 1
                  If fileExtension = allowedExtensions(i) Then
                      fileOK = True
                  End If
              Next
              If fileOK Then
                  Try
                      FileUpload1.PostedFile.SaveAs(path &amp; _
                           FileUpload1.FileName)
                      Label1.Text = "File uploaded!"
                  Catch ex As Exception
                      Label1.Text = "File could not be uploaded."
                  End Try
              Else
                  Label1.Text = "Cannot accept files of this type."
              End If
          End If
      End Sub
  </code></pre>