0

I am trying to add a Button "Clear Files" that should not interact with the RadAsyncUpload control.

The problem is that if the client selects a couple files to upload. But then scraps that idea and clicks the Clear All Files link.. the files will upload / process anyway.

I have tried to by pass with jQuery calls to the btnClearALL_clicked method etc.. but nothing is working.

How do I stop files from uploading if I am trying to trigger other functionality (that happens to do a postback) on the same page?

<asp:Panel ID="viewWrapperTab2" runat="server">
    <div id="viewWrapper2" style="text-align: center;">
        <div class="contentUpload">
            ...<br />
            <br />
            ..
            <telerik:RadAsyncUpload runat="server" ID="multiFileUploadA" MultipleFileSelection="Automatic"
                OnFileUploaded="multiFileUploadA_FileUploaded" />
            <br />
            <br />
            ..
            <telerik:RadAsyncUpload runat="server" ID="multiFileUploadB" MultipleFileSelection="Automatic"
                OnFileUploaded="multiFileUploadB_FileUploaded" />
            <br />
            <br />
            <asp:Button ID="btnUpload" runat="server" Text="Upload Files" />
            <telerik:RadProgressArea runat="server" ID="RadProgressArea2" />
        </div>

        <asp:LinkButton ID="btnClearAll" onclick="btnClearAll_Click" runat="server" Text="Clear Files" />
    </div>
</asp:Panel>

How do I segregate controls that both do post-backs? FYI: everything is working fine.. I just need btnClearAll_clicked to cancel out multiFileUploadA_FileUploaded from running in the code behind or bypass it completely.

Is there a way to change the firing order in the code-behind? protected void multiFileUploadA_FileUploaded(object sender, FileUploadedEventArgs e){} is firing before protected void btnClearAll_Click(object sender, EventArgs e){}

Tony L.
  • 17,638
  • 8
  • 69
  • 66
JoJo
  • 4,643
  • 9
  • 42
  • 65

4 Answers4

2

deleteFileInputAt() method should remove all files on the client:

            function deleteAllFiles() {
            var upload = $find('RadAsyncUpload1');
            for (var i = 0; i < upload.getUploadedFiles().length; i++) {
                upload.deleteFileInputAt(i);
            }
        }
Hristo
  • 859
  • 1
  • 8
  • 14
1

This will be done on the client side. Since you are using javascript to submit the files for upload, you should be able to add a listener to the xhr object to watch for progress. Something like this:

xhr.upload.addEventListener('progress', function(e){
    if(haltUpload) {
        xhr.abort();
    }
}, false);

You may also want to alert the server the file(s) have been aborted to prevent their processing.

Chris Peterson
  • 713
  • 7
  • 13
1

to be clear so I can try help here are we talking about removing them once they have uploaded or cancelling whilst they are still being uploaded as this isn't very clear in the question and reading other people's answers hasn't helped me to determine which you mean.

harrison
  • 79
  • 1
  • 11
  • This would be they have already been queued in FileUpload so they *may* have made it to the Temp folder but I don't think they have uploaded as the postback will finalize that. That is why it is so important to NOT have a postback. – JoJo Oct 31 '14 at 12:44
  • 1
    if you check your temp fileDataStore are they in there or not yet, and in an mvc website im working on we have used a postback method with an implement of removing all from a tempdatastore(file) and a method to prevent them from finishing the actual upload - (never making it to the tempDatastore). that is why i ask and you should consider a postback, it helps keep it up to date and its really not that bad. – harrison Oct 31 '14 at 14:33
1

You can remove runat="server" so there will be no postback and then use function deleteAllFiles() (as suggested above)to remove files on client