title: ASP.net AsyncFileUpload: How to send Exceptions messages from the 'UploadedComplete' event to the client function 'uploadError'
body: <p>I've been following this <a href="http://technico.qnownow.com/using-asyncfileupload-control-in-asp-net-ajax/" rel="nofollow">tutorial</a> , but I got a problem.</p>
  
  <p>If an exception is thrown in the UploadedComplete event </p>
  
  <pre><code>protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
          {
              try
              {
                  string importPath = MapPath("~/docs/imports/");
                  string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + Path.GetFileName(e.FileName);
  
                  //pass filename to front end;
                  ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "newfile"
                      , "window.parent.$find('" + AsyncFileUpload1.ClientID + "').newFileName='" + filename + "';", true);
  
                  AsyncFileUpload1.SaveAs(importPath + filename);
              }
              catch (Exception ex)
              {
                  ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "size", "top.$get(\"" + lblUploadStatus.ClientID + "\").innerHTML = 'There was an Error Processing the Request : Error " + ex.Message.ToString() + "';", true);
  
              }
          }
  </code></pre>
  
  <p>I want the exception message shown in the label that is below the AsyncFileUpload control.</p>
  
  <p>I thought that using a try catch and passing the message using  ScriptManager.RegisterClientScriptBlock would be enough and that message will be passed to this client side function</p>
  
  <pre><code>function uploadError(sender, args) {
              var errmsg = args.get_errorMessage();
              updateUploadStatus("error", "There was Error Uploading the file. Error :" + errmsg);
          }
  </code></pre>
  
  <p>But even if a exception is thrown, the controls ignores it and show a successful message.</p>
  
  <p>I also noticed that the status parameter in this function never gets updated. It is always "success"</p>
  
  <pre><code>function updateUploadStatus(status, message) {
              var uploadstatlbl = $("span[id$='lblUploadStatus']");
              uploadstatlbl.html(message);
              if (status == "error") {
                  uploadstatlbl.removeClass("spansuccess").addClass("spanerror");
              } else {
                  uploadstatlbl.removeClass("spanerror").addClass("spansuccess");
              }
          }
  </code></pre>
  
  <p>Do you have any idea what can be causing this???</p>
  
  <p>Thanks in advance.</p>