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

Async upload how to reset control in OnClientFileSelected when file is not valid?

10 Answers 296 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 10 Nov 2011, 08:38 PM
Hello -

I'm using the the RadAsyncUpload and i've wired up a client side handler to the OnClientFileSelected event. My goal is to alert the user that their file is not a valid extension and then  reset the control by removing the file that they attempted to upload. According to your documentation here I should be able to make use of the remove_fileSelected method to remove the file that the user attempted to upload and thus hopefully reset the control so the user can do a new upload.

The problem I have is I can't find any documentation on your site for what the signature is for remove_fileSelected or how it should be used - what parameter needs to be passed to it. Here is my handler code, please help, and if possible please expound your documentation so this is more clear.

Thanks.

this.checkFileExtension = function (radUpload, args) {
    if (!radUpload.isExtensionValid(args.get_fileName())) {
        alert('Please upload images with .jpg, .gif, .png, .bmp, or .tif extensions.');
        radUpload.remove_fileSelected();
    }
}



10 Answers, 1 is accepted

Sort by
0
Peter Filipov
Telerik team
answered on 14 Nov 2011, 06:07 PM
Hi Ian,

The remove_fileSelected method removes the event handler of the OnClientFileSelected event. The following sample code implements your scenario:

<form id="form1" runat="server">
<div>
    <telerik:RadScriptManager runat="server" ID="RadScriptManager">
    </telerik:RadScriptManager>
    <telerik:RadAsyncUpload ID="RadAsyncUpload1" runat="server" ViewStateMode="Enabled"
        AllowedFileExtensions=".png"
         OnClientValidationFailed="onClientValidationFailed">
    </telerik:RadAsyncUpload>
</div>
</form>
<script type="text/javascript">
 
    function onClientValidationFailed(sender, args) {
        $telerik.$(".ruCancel").parent().remove();
        alert("Allowed files extension is png");
    }
 
</script>


Regards,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Ian
Top achievements
Rank 1
answered on 19 Nov 2011, 12:40 AM
This doesn't work. It just removes the whole control (probably because I have max file inputs set to 1), I still want the user to be able to select a different file after they've attempted upload of an invalid file. Please advise, thanks.
0
Peter Filipov
Telerik team
answered on 22 Nov 2011, 12:36 PM
Hello Ian,

The RadAsyncUpload disappears because the MaxFileInputsCount is set to 1. Please try the following sample code to avoid that behavior.
<form id="form1" runat="server">
<div>
    <telerik:radscriptmanager runat="server" id="RadScriptManager">
</telerik:radscriptmanager>
    <telerik:radasyncupload id="RadAsyncUpload1" runat="server" viewstatemode="Enabled" MaxFileInputsCount="1"
        allowedfileextensions=".png" onclientvalidationfailed="onClientValidationFailed">
</telerik:radasyncupload>
</div>
</form>
<script type="text/javascript">
    function onClientValidationFailed(sender, args) {
        $telerik.$(".ruCancel").parent().remove();
        alert("Allowed files extension is png");
        sender.addFileInput();
    }
</script>


Best wishes,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Ian
Top achievements
Rank 1
answered on 22 Nov 2011, 06:04 PM
This seems to work well, thanks.

On a side note I've used Telerik products for several years, I would sum up my experience with your controls like this: great controls with terrible documentation. Surely i'm not the only one to comment on this, is this is something Telerik could improve? I think it needs more concrete examples and descriptions for each public method and property that is available on each control.

0
Peter Filipov
Telerik team
answered on 24 Nov 2011, 12:08 PM
Hi Ian,

Thank you for your feedback. We will do our best to update the documentation. Regarding the RadAsyncUpload documentation you can find here all the methods used in the example below.

All the best,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Lobna
Top achievements
Rank 1
answered on 09 Jan 2013, 12:10 PM
when I try to upload file with RadAsyncUpload, it crashes when the file is open. 
How to solve this?
Thanks
0
Peter Filipov
Telerik team
answered on 14 Jan 2013, 08:23 AM
Hello Lobna,

We had similar issue which is resolved in the latest version of our controls. Do you reproduce the issue on our online demos?

Regards,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Lobna
Top achievements
Rank 1
answered on 14 Jan 2013, 01:52 PM
Thanks for your reply.

No, on online demos there is no such problem. So I think I need to update my Version.
I have v.2012.2.815.40, so I need to update it, right?
0
Peter Filipov
Telerik team
answered on 17 Jan 2013, 08:20 AM
Hello Lobna,

Actually the issue is possible to come from the version of your Silverlight/Flash plugins. Before downloading the latest version of our controls you could try to set DisablePlugins property to true.

Regards,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Lobna
Top achievements
Rank 1
answered on 19 Jan 2013, 07:22 AM
Hello Peter,

It works fine after changing the 'DisablePlugins' property to true.

Thanks alot,
Tags
AsyncUpload
Asked by
Ian
Top achievements
Rank 1
Answers by
Peter Filipov
Telerik team
Ian
Top achievements
Rank 1
Lobna
Top achievements
Rank 1
Share this question
or