Adding State Variable to the Upload

Jul 2, 2009 at 2:28 PM


Ive read a number of discussions on passing a state variable as well as tried your solutions.  If I use non-amazon file uploader adding state is no problem, however since amazon uploader does not allow RequestAsPostBack to be set to true, I have tried passing the state via javascript.  So far no luck.  Can you show just a very simple of example of this working?

 function FileStateChanged(uploader, file, httpStatus, isLast){

                        alert('state change');

                         <%= FileUploaderFlvAmazon.ClientID %>.setStateVariable("TestVar1", "TestState1");


<fjx:FileUploader ID="FileUploaderFlvAmazon" JsFunc_FileStateChanged="FileStateChanged"   runat="server"  >


                          <fjx:DirectAmazonUploader   ConfirmUploadJsFunc="ConfirmUploadJsFunc"  OnConfirmUpload="FileUploaderFlvAmazon_ConfirmUpload" 









As you click 'Upload' you would expect to see something inside the Request object

protected void Page_Load(object sender, EventArgs e)


        Debug.WriteLine("Passed value:" + this.Request.QueryString["TestVar1"];   // prints empty value

      // and if you do a forloop on the Request object, the expect 'TestVar1' doesnt exist


     // I have also tried adding the var on the server side just to see if it makes any difference

    //  FileUploaderFlvAmazon.State.Add(etc,etc)





The control has been working fine thus far, and this is the last thing that I need to get going properly...

Thanks for your support.

Aug 17, 2009 at 1:22 AM

Hi wojouk,

Any luck on this?  I'm having a similar issue with the DirectAmazonUploader. 

I'm trying to store information into a database about the file that is being uploaded.  And I want to be able to catch errors and display an error message to the user.  for example, if there is an error inserting into the database, i want to cancel the upload and display an error message.  And I thought I could change a statevariable or I could change the  'HttpContext.Current.Response.StatusCode to a custom code to show an error.  But it seems both theses methods need a postback.  Any ideas?

Aug 24, 2009 at 4:57 PM

Hi kbende,

I never solved this particular problem...I tried a few things and eventually gave up - could not justify any more time on it since my users are internal company admins.

However, if you come across a solution, let me know as I certainly remember the frustrations on this one.



Aug 24, 2009 at 7:45 PM

Please get the latest version from with the same key and you will be able to do that:


<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Register TagPrefix="fjx" Namespace="com.flajaxian" Assembly="com.flajaxian.FileUploader" %>
<%@ Register TagPrefix="fjx" Namespace="com.flajaxian" Assembly="com.flajaxian.DirectAmazonUploader" %>
<script runat="server">
private void FileUploaderFlvAmazon_ConfirmUpload(object sender, ConfirmUploadEventArgs e)
    throw new ApplicationException("##" + e.Name + "##" +"Some error type" + "##");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="" >
<head runat="server">
    <script type="text/javascript">
    function ConfirmUploadJsFunc(r) {
        if (r.isError) alert("Error File: " + r.pageContent.split("##")[1].split("##").join("")+ "\n" + 
                             "Error Type: " + r.pageContent.split("##")[2].split("##").join(""));
    <form id="form1" runat="server">
        <fjx:FileUploader ID="FileUploaderFlvAmazon" runat="server">
              <fjx:DirectAmazonUploader ConfirmUploadJsFunc="ConfirmUploadJsFunc" OnConfirmUpload="FileUploaderFlvAmazon_ConfirmUpload" 



Aug 26, 2009 at 1:15 PM

Thanks for the reply, I will take a look at this within the next few days.


Aug 27, 2009 at 2:22 PM

Hi vladb,

I was able to get the code with working the latest version of the directuploader libraries.  But I wasn't able to throw an exception in the FileNameDeterming event.  When I throw the exception in the ConfirmUpload event, it works.  What's the reasoning behind that?

Aug 27, 2009 at 4:33 PM

In the example I use OnConfirmUpload

Aug 27, 2009 at 6:09 PM

Why can't I use the OnFileNameDetermining?


Aug 27, 2009 at 8:59 PM

Because OnFileNameDetermining is called on the initial ajax call before any file has been transfered. You should only use it to change file names, anything else should go to OnConfirmUpload otherwise you can't be sure that you will ever get there.

Use fiddler to see what and when is happening

Sep 5, 2009 at 7:38 PM

Thanks for the example, I was able to get that to work.  I throw an error and can parse it and display the message to the user the way you should me.  But when I upload 2 or more files that have errors, I can only retrieve the last file that had an error.  I see in fiddler both responses with errors, but in the ConfirmUploadJsFunc, I can only see the last error.  Is there any way to get all errors?

Also, if all files have been uploaded successfully, is there a way in ConfirmUploadJsFunc to loop through the response and show all filenames that have been uploaded successfully?


Thanks for the help.