This is a migrated thread and some comments may be shown as answers.

How to prevent file delete from onclientdeleting event

4 Answers 174 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
chandrasekhar
Top achievements
Rank 1
chandrasekhar asked on 21 Oct 2010, 04:22 PM

Hi,
i want to prevent file deletion on click of "Cancel" from confirmation alert

<telerik:RadAsyncUpload ID="radUpload" runat="server" OnClientValidationFailed="validationFailed" TemporaryFileExpiration="5"        OnClientFileSelected="fileSelected" OnClientDeleting="fileDelete" OnClientFileUploaded ="fileUploaded">
</telerik:RadAsyncUpload>

function fileDelete(sender, args) {
     
        if (confirm("Are you sure to Delete the record?"))  {
            args._cancel = false;       
        }
        else {
            args.set_cancel(true);        
            //args._cancel = true;
            //sender._cancelEvent();
        }
    }

How to prevent file deletion on click of "Cancel" button.

On click of "Cancel" it is not not deleting from row, but actually file is deleted from control. So on click of Cancel button i want to prevent the file delete from control also.

Thanks,
Chandra.T

4 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 22 Oct 2010, 09:57 AM
Hi chandrasekhar,

I've managed to get this working using the following code:

    <script type="text/javascript">
        function fileDeleting(sender, args) {
            if(!confirm("Are you sure that you want to delete the file?"))
                args.set_cancel(true);
        }
     
    </script>
 
        <telerik:RadAsyncUpload runat="server"
            ID="RadAsyncUpload1"
            AllowedFileExtensions="jpeg,jpg,png"
            OnClientDeleting="fileDeleting">
         
        </telerik:RadAsyncUpload>


Greetings,
Genady Sergeev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
chandrasekhar
Top achievements
Rank 1
answered on 22 Oct 2010, 12:32 PM
Hi Genady Sergeev,
Thanks for your reply.

On click of "x Remove" i am displaying confirmation alert with "OK" and "Cancel".
If you click OK or Cancel, surely the file will be deleted from upload control; but The only difference is if you click "Cancel" that file will not be delete from UI but internally in control the file will be deleted.

Note: Upload two files; and click on "x Remove" for one file; click on "Cancel".
Still you are able to see two files; but if you check the files count in code behind you will get file count 1. not 2.
(radUpload.UploadedFiles.Count)
Because once user clicks on "x Remove" the file will be deletes.
With Cancel only we can prevent the display;
But i want to prevent both display and file delete on click of "Cancel"

Help me....

Thanks,
Chandrasekhar.T
0
Genady Sergeev
Telerik team
answered on 27 Oct 2010, 03:31 PM
Hi chandrasekhar,

Thank you for pointing this problem to us. Please use the following JavaScript in order to workaround the problem. You need to paste it right after the ScriptManager declaration:

Telerik.Web.UI.RadAsyncUpload.prototype.deleteFileInputAt = function(index, skipEvent) {
        var row = $telerik.$(this._getRow(index));
             
            if (!Telerik.Web.UI.RadAsyncUpload.callBaseMethod(this, 'deleteFileInputAt', [index, skipEvent]))
                return;
                 
            var fileInfo = row.data('fileInfo');
            Array.remove(this._uploadedFiles, fileInfo);
            this.updateClientState();
 
            this._uploadModule.rowRemoved(row);
 
            var shouldAddInput = row.parent().children().has('.ruFakeInput').length == 0;
 
 
 
            if (shouldAddInput && this._autoAddFileInputs)
                this.addFileInput();
        }

Also, I've updated your telerik points for the report.

Regards,
Genady Sergeev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
markhugy
Top achievements
Rank 1
answered on 02 Dec 2010, 12:26 PM
Here is a good tool to find and delete duplicate files
www.duplicateFilesDeleter.com
Tags
AsyncUpload
Asked by
chandrasekhar
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
chandrasekhar
Top achievements
Rank 1
markhugy
Top achievements
Rank 1
Share this question
or