Search code examples
c#asp.nettelerikasyncfileupload

How to prevent FileUpload from continuing if Clear LinkButton clicked?


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){}


Solution

  • 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);
                }
            }