title: Asp.net file upload validation with jquery
body: <p>I am using the below jquery function to do client side validation for an asp.net file upload control.</p>
  
  <pre><code>function setUplaodButtonState() {
      var maxFileSize = 4096000 // 4MB -&gt; 4000 * 1024
      var fileUplaod = $("#&lt;%=flupldSignUpDocuments.ClientID%&gt;");
  
      if (fileUplaod.val() == '') {
          return false;
      } else {
          if (fileUplaod[0].files[0].size &lt; maxFileSize) {
              $("#&lt;%=lblfilesizerror.ClientID%&gt;").html("");
              return true;
          } else {
              $("#&lt;%=lblfilesizerror.ClientID%&gt;").text('File is Larger than recommended size');
  
              var file = document.getElementById("&lt;%=flupldSignUpDocuments.ClientID%&gt;");
              $(file).parent().html($(file).parent().html());
  
              return false;
          }
      }
  }
  </code></pre>
  
  <p>The first time a user uploads a file greater that the specified file size the error is shown and also the fileupload box is cleared of any content. However, on trying the second time around with the same file that is greater than the recommended size the box is not cleared.</p>