locked
AjaxFileUpload UploadCompleteAll not firing RRS feed

  • Question

  • User-1952463932 posted

    This is weird.

    I'm using the AjaxFileUpload to upload customer pictures about their place of business to our site so that we can show them to perspective clients for those businesses.  We allow up to 5 pictures.  The AjaxFileUpload control is inside a div1 to begin with.  If the user uploads 2 pictures for example then the AjaxFileUpload controls is moved to div3 and then the maximum number of files is set to 3.  Everything works great as long as I don't try to upload a 5th file.  Doesn't matter if it is a single file that will be the 5th picture or 5 files at a time because there were no pictures to begin with or any other combination as long as it is not the last file.

    So you might think that there is something in the 5th div that causes the problem. There is no difference in the asp or html controls (except for the id's).  Even if I change the maximum number to 4 then it is the 4th file that has the issue, in the 4th div, even though no asp or html controls have been changed.  As long as the last file is not uploaded both the server side and the client side UploadCompleteAll fires just fine.

    Also in all cases the UploadComplete even fires perfectly and I can get the file and process it.

    I don't understand at all what to even try to either debug or how to work around the problem.

    Any help greatly appreciated.

    Thursday, May 21, 2015 4:29 AM

Answers

  • User-1952463932 posted

    Update!

    The problem as been solved,  After banging my head against a wall and trying to find anything on the matter I rebuild the page and the same problem persisted.  However this time I was getting a JSON error so I googled it.  While reading posts on that error I cam across one that mentioned visibility; and everything fell into place.  You can't set the AjaxFileUpload's Visible property to false because then when the page is updated the control doesn't exist, not just invisible.  So instead I used style="display:none", and everything started to work.

    Yech!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 25, 2015 5:28 PM

All replies

  • User1644755831 posted

    Hello tdinpsp,

    Even though your explanation is perfectly clear I am not able to just assume correct answer based on it. It would allow the community for answer you more better if you put some minimum code that they can guess what might be wrong or what might you should do to resolve your problem.

    With Regards,

    Krunal Parekh

    Friday, May 22, 2015 2:24 AM
  • User-1952463932 posted

    Sure here is some of the ASPX code.

    <div id="divImage1" runat="server" ClientIDMode="Static" ondrop="drop(event)" ondragover="allowDrop(event)">
        <asp:Image runat="server" ID="Image1" Height="180px" Width="240px" draggable="true" ondragstart="drag(event)"/>
        <cc1:AjaxFileUpload runat="server" ID="afuFileUpload1" Width="400px" MaximumNumberOfFiles="1" 
            OnUploadComplete="afuFileUpload1_UploadComplete" OnUploadCompleteAll="afuFileUpload1_UploadCompleteAll" 
            Height="180px" OnClientUploadStart="showWaitCursor" OnClientUploadCompleteAll="uploadCompleteAll" />
    </div>
    

    There are 4 more divs like divImage1 and they contain only an asp:Image control, there is no AjaxFileUpload control.  At first when there are no pictures Image1 is not visible and only the AjaxFileUpload is.  The maximum number of files is set to 5.  Let's assume that the user uploads only one file.  Then Image1 becomes visible and displays the image that was uploaded.  And from the code-behind the parent control for the AjaxFileUpload is set to divImage2, and divImage2 is made vsibile.

    I cannot set the parent of the AjaxFileUpload when the server side OnUploadCompleteAll fires so instead when the OnclientUploadCompleteAll fires I do a post back (__doPostBack).

            function uploadCompleteAll() {
                __doPostBack("uploadCompleteAll", "");
            }
    

    The is the client side function that is called when CompleteAll should fire.

    It's during that post back I'm able to set the parent properly.

    divImage2.Controls.Add(afuFileUpload1);
    

    At this point I also set the maximum number of files to 4.

    Now lets say the user uploads 1 file again.  The process repeats itself except this time Image2 becomes visible with the new image, and divImage3 becomes the parent of the AjaxFileUpload.  The can continue one file at a time, or more up to the point where a 4 images are uploaded.  However any combination where the fifth file is uploaded whether it be five files at once or a single file because there are already 4 or anything in between neither the client or the server side complete events fire.  The server side UploadComplete event however does fire.  So all five files make it to the server and are available to be displayed but because the complete event never fires the page never sees them.

    I even tried to force the page to do a redirect to itself within the OnUploadComplete if it was for the 5th file, but even that has no effect.  If however you manually refresh the page <F5> or navigate to a different page and back, everything is good.

    There are a couple of other things going on here at the same time: reorder, and delete.  Reordering the images is done by dragging and dropping an image from one div to another.  When this occurs I fire a __doPostBack and the server code reorders the images and shows them in the appropriate image control.  Note that this means that Image1 will always be in divImage1 and so on, it is the image information that is updated for the image control.  Delete is done using a standard button that becomes visible below the image when the image control is actually displaying an image.  If the user clicks the delete button then the server side code drops the image data for that particular image and then moves the image data from other images appropriately and then hides the last image control, and shows the AjaxFileUpload control in the appropriate place.  For example if there were 5 images and the user deleted image 3, nothing would happen to images 1 and 2, however image 4 would now be displayed in the Image3 control, and image 5 in the Image4 control.  The Image5 control would be made invisible, and the AjaxFileUpload control would be made visible and have its parent set to divImage5.

    Friday, May 22, 2015 3:02 AM
  • User-1952463932 posted

    So an added bit of information, on a "real" server, as opposed to my development machine.  The complete all never fires no matter which file or how many files.

    Sunday, May 24, 2015 8:00 PM
  • User-1952463932 posted

    Update!

    The problem as been solved,  After banging my head against a wall and trying to find anything on the matter I rebuild the page and the same problem persisted.  However this time I was getting a JSON error so I googled it.  While reading posts on that error I cam across one that mentioned visibility; and everything fell into place.  You can't set the AjaxFileUpload's Visible property to false because then when the page is updated the control doesn't exist, not just invisible.  So instead I used style="display:none", and everything started to work.

    Yech!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 25, 2015 5:28 PM