locked
Accessing form variables with AjaxControlToolkit's AjaxFileUploader RRS feed

  • Question

  • User-1561933206 posted

    Hi,

    I am trying to use AjaxFileUploader to upload files. The file upload works fine.

    But, I would like to access a form variable as part of AjaxFileUploader's OnUploadCompleteAll function (server side) but its not available in

    codebehind for some reason. This function is called on the click of Upload button when all the uploads are complete.

    <asp:TextBox ID="_branchTxtBox" runat="server" MaxLength="3"></asp:TextBox>
    
    <asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server" OnUploadCompleteAll="AjaxFileUpload1_UploadCompleteAll"/>

    In the codebehind, I have

    protected void AjaxFileUpload1_UploadCompleteAll(object sender, AjaxFileUploadCompleteAllEventArgs e)
     {
    
        string branchNumber = _branchTxtBox.Text.ToString(); // empty
     }

    Any thoughts why the branchNumber is empty in codebehind?

    Thanks

    Tuesday, April 22, 2014 4:42 PM

Answers

  • User-760709272 posted

    The ajax file uploader doesn't submit the whole form as a normal postback, it wil only post the file itself.  You could examine Request.Form to see if any of the other form fields are in there, but I'm not sure they will be.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 22, 2014 5:02 PM
  • User-760709272 posted

    My advice would be to scrap the whole idea of the asynch upload and just use a normal one.  If you are stuck on the asynch idea you'll need to gather all the other data first and validate it, and then when the only thing you need is the file, at that point you can present them the asynch uploader.  Or look for a third-party asynch plug-in that also lets you submit the fields from a form.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 22, 2014 6:02 PM

All replies

  • User-760709272 posted

    The ajax file uploader doesn't submit the whole form as a normal postback, it wil only post the file itself.  You could examine Request.Form to see if any of the other form fields are in there, but I'm not sure they will be.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 22, 2014 5:02 PM
  • User-1561933206 posted

    Hi AidyF,

    Thanks for the reply.

    Request.Form isnt giving me anything in codebehind.

    Actually I would like to do some validation before uploading. If form variables are empty, then I would like to cancel the upload operation.

    So I tried using AjaxFileUpload's OnClientUploadStart="OnClientUploadStart"  

    function OnClientUploadStart() {
            var branchNumber = document.getElementById("_branchTxtBox").Value;
            if (branchNumber == "")
                return false;
        }

    pops up saying branchNumber is undefined.

    Any other thoughts please?

    Tuesday, April 22, 2014 5:31 PM
  • User-760709272 posted

    My advice would be to scrap the whole idea of the asynch upload and just use a normal one.  If you are stuck on the asynch idea you'll need to gather all the other data first and validate it, and then when the only thing you need is the file, at that point you can present them the asynch uploader.  Or look for a third-party asynch plug-in that also lets you submit the fields from a form.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 22, 2014 6:02 PM
  • User-1561933206 posted

    The problem with normal file upload control is that it doesnt allow multiple files to be selected and uploaded. 

    Thanks anyway. I will keep this thread open for a while to see if there is any other probable solution.

    Tuesday, April 22, 2014 6:12 PM