cannot get file to upload prior to server side code running

Last post 01-14-2010, 7:32 PM by cutechat. 1 replies.
Sort Posts: Previous Next
  •  01-14-2010, 12:09 PM 58170

    cannot get file to upload prior to server side code running

    I want to have an uploader on a form where a file is only uploaded and then saved if there happens to be one queued up. So i want the upload to take place on the save event. I like the queue that your uploader uses I just need the uploader to finish prior to my code behind function for the save process running. 
     
    I am using the following code
     
                            <CuteWebUI:UploadPersistedFile runat="server" ID="upfUploadNewFile" AutoUseSystemTempFolder="false"
                                 InsertButtonID="lbUploadNewFile" ManualStartUpload="true" MaxFilesLimit="1" MultipleFilesUpload="false"
                                 OnFileUploaded="FileUploaded" />
      
    of which my button is
     
              <asp:Button runat="server" ID="btnSave" Text="Save" OnClick="btnSave_OnClick" OnClientClick="return btnSave_OnClientClick()" />

    as you can see my button calls a client side function then the serverside
     
            function btnSave_OnClientClick() {
                var uploadobj = document.getElementById('<%=upfUploadNewFile.ClientID %>');

                if (uploadobj.getqueuecount() > 0) {
                    uploadobj.startupload();
                }
                
                return true;
            }
      
    as you can see i only trigger the javascript startupload() function if there is a file queued up
     
        protected void btnSave_OnClick(Object sender, EventArgs e)
        {
            Int32 FileID = 0;

                if (upfUploadNewFile.File != null)
                {
                    FileID = HandleFileUpload().fileID;
                }
               
         } 
     
     for some reason when my server side function runs the (upfUploadNewFile.File != null) always return false and the serverside saving doesnt occur
     
     
     How can I resolve this issue?
     
     
  •  01-14-2010, 7:32 PM 58174 in reply to 58170

    Re: cannot get file to upload prior to server side code running

    Hi,
     
    Please check the HTML code of this page http://ajaxuploader.com/Demo/Start-uploading-manually.aspx
     
    in btnSave_OnClientClick, if call startupload(), you should return false to prevent the page submit.
     
    and you need handle the CuteWebUI_AjaxUploader_OnPostBack event for submitting the form by the button again.
     
    Regards,
    Terry
View as RSS news feed in XML