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

ASyncUpload Issue?

1 Answer 154 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Jerry
Top achievements
Rank 1
Jerry asked on 17 May 2010, 06:52 PM
Forgive me for just asking to see if anyone else has encountered this issue rather than ripping my application infrastructure apart so that I can upload a test for you guys, but...

I'm using the ASyncUpload on a content page and an AjaxManagerProxy since my AjaxManager is in my master page. My upload is based a lot like the sample where I select an image an upload immediately. After the image is uploaded and processed on the FileUploaded event, I update an asp:image and a RadComboBox. This all seems to be good.

My problem is that the new image filename is added to the combobox and the user is allowed to select the new filename or a pre-existing image filename. When the new file is uploaded, I auto select that filename in the combobox and update the image too. Works fine... However, if I go ahead and select a different file now, the combobox's event fires, but so does the FileUploaded event. ???

The combobox (and a bunch of other controls) on the form are Ajaxified. Any of these postback events will now trigger the FileUploaded event if I've previously uploaded a file.

After the initial FileUploaded event, I clean out the file list by using deleteFileInputAt(0) in javascript, as shown in the example. This does remove it from the client UI. But does this really remove it from the control?

Also, I cannot seem to debug this problem within Visual Studio (2010)'s development server. When I step through the code in the FileUploaded() event, any time I try to access e.File.InputStream, I get an exception that the file is already in use.

This event shouldn't be executing when something else is causing the postback, such as my combobox or checkbox (on a radtree).

My way around this was to catch the exception by calling e.File.SaveAs() with a different filename. If it fails, it's most likely not the proper event that fired. If the SaveAs() is successful, I just rename the file after the successful save since this must be the proper event firing.

So, I have my workaround, but it's very odd behaviour... I really don't have a lot of time to rebuild a test app or start ripping code out so that I can upload what I have, so, I hope I've given enough of a description for you guys to try this and see what you make of it.

Thanks,
J

1 Answer, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 19 May 2010, 04:18 PM
Hi Jerry,

Please, make sure that you correctly update the RadAsyncUpload on ajax calls. When a postback is triggered,  no matter async or a normal one, the async upload will trigger its File_Uploaded event if its client state says there are files uploaded. So far so good. However, if after the postback the upload is not updated with the server response, on a subsequent postback (say the one from the combo) he will fire its event one more time. The reason for this is that its client state was not updated during the last postback. To illustrate this I will give you an example. Suppose that we have button that shows Panel. Here is the AjaxManager declaration:

<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
       <AjaxSettings>
           <telerik:AjaxSetting AjaxControlID="Button1">
               <UpdatedControls>
                   <telerik:AjaxUpdatedControl ControlID="Panel1" />
               </UpdatedControls>
           </telerik:AjaxSetting>
       </AjaxSettings>
   </telerik:RadAjaxManager>

In addition to showing the panel, this postback will fire the async upload event as well. However, since the AsyncUpload is not in the list of updated controls its client state wont be updated. To workaround this the following approach should be used:

<telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="Button1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="Panel1" />
                    <telerik:AjaxUpdatedControl ControlID="RadAsyncUpload1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>

Please notice that now the async upload is in the list of updated controls. This will fix the issue that you experience. We will delve into this issue and try to fix the upload in a way that it will now when to save and not to save the files. However, for now, the described approach should be used.

Kind 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.
Tags
AsyncUpload
Asked by
Jerry
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Share this question
or