I have a problem when using the args.set_cancel command (true), to cancel the upload.
Code RadAsyncUpload:
<telerik:RadAsyncUpload
ID="radFileUpload"
MaxFileSize="10000000"
OnClientFilesSelected="OnClientFilesSelected"
HttpHandlerUrl="~/UploadFiles.ashx"
TemporaryFolder="~/upload"
MaxFileInputsCount="1"
runat="server">
</telerik:RadAsyncUpload>
Code Javascript:
function OnClientFilesSelected(sender, args) {
if ((sender._uploadedFiles.length + args.get_count()) > sender._maxFileCount) {
args.set_cancel(true);
alert('The maximum number of file(s) to upload is: ' + sender._maxFileCount);
}
}
The problem is that when the seto args.set_cancel to TRUE, the upload component does not finciona more. By clicking on the button to upload, it does not respond anymore. This is the version 2016.2.504.45. In version 2015.1.401.45 it works normally.
8 Answers, 1 is accepted
A solution I found to get around this problem was:
I wonder when you release a version of correction?
<telerik:RadAsyncUpload
ID=
"radFileUpload"
MaxFileSize=
"10000000"
OnClientFilesUploaded=
"OnClientFilesUploaded"
OnClientFilesSelected=
"OnClientFilesSelected"
OnClientFileUploading=
"OnClientFileUploading"
HttpHandlerUrl=
"~/UploadFiles.ashx"
TemporaryFolder=
"~/upload"
MaxFileInputsCount=
"1"
runat=
"server"
>
</telerik:RadAsyncUpload>
function
OnClientFilesUploaded() {
if
(isCanceled &&
elements.length > 0) {
$.each(elements,
function
(index, value) {
$(value._row).find(
'input[name="RowRemove"]'
).click();
});
}
}
function
OnClientFilesSelected(sender, args) {
if
((sender._uploadedFiles.length + args.get_count()) > sender._maxFileCount) {
isCanceled =
true
;
alert(
'The maximum number of file(s) to upload is: '
+ sender._maxFileCount);
}
else
{
isCanceled =
false
;
}
}
var
elements = [];
function
OnClientFileUploading(sender, args) {
if
(isCanceled) {
elements.push(args);
}
else
{
elements = [];
}
}
I have recorded the following video which shows the RadAsyncUpload, setup with OnClientFilesSelected and canceling the upload within the client-side event with set_cancel(true). As you can see at my end the uploading is canceled as it should.
I'm using version 2016.2.504.45.
Regards,
Anton
Telerik by Progress
Hi Anton,
Attached the video that I did.
I did not express myself very well in relation to the problem occurred.
The command 'args.set_cancel (true);' works yes, however when using the command and then try to add a new file, it does not add, or upload no more anexma any files.
In my case I add a validation. Our upload for example can only be inserted 5 files, if user add 6 files, the system validates and bar the action using the 'args.set_cancel (true);'.
If you put 6 files the system cancels the action and displays a message, causing the user to add only 5 files. After the validation is performed and the user attempts to re-add other files, the upload does not add the files in the list.
Try to simulate the implementation below, filling methods.
01.
<telerik:RadAsyncUpload
02.
03.
ID=
"radFileUpload"
04.
MaxFileSize=
"10000000"
05.
OnClientFilesSelected=
"OnClientFilesSelected"
06.
HttpHandlerUrl=
"~/UploadFiles.ashx"
07.
TemporaryFolder=
"~/upload"
08.
MaxFileInputsCount=
"5"
09.
MultipleFileSelection=
"Automatic"
10.
runat=
"server"
>
11.
</telerik:RadAsyncUpload>
12.
13.
14.
15.
16.
function
OnClientFilesSelected(sender, args) {
17.
18.
if
((sender._uploadedFiles.length + args.get_count()) > sender._maxFileCount) {
19.
args.set_cancel(
true
);
20.
alert(
'The maximum number of file(s) to upload is: '
+ sender._maxFileCount);
21.
}
22.
}
Sorry, here is the link to the video.
https://www.youtube.com/watch?v=R9eQ0v_15S4
Unfortunately I was unable to reproduce the issue you're facing. I used the code you've provided and followed the steps shown in your video, but at my side it seems to work as it should. Please take a look at the video I've recorded and let me know if additional steps need to be followed in order for the problem to be reproduced.
Regards,
Anton
Telerik by Progress
Hi Anton,
The video you have done is correct so, follow all the steps correctly. I would like me to send this project that you used to record video?
Thank you very much.
I'm attaching the page I tested with.
Regards,
Anton
Telerik by Progress