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

FileUploaded Causing Issues

2 Answers 48 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 2
Ron asked on 27 Jan 2014, 05:05 PM
Hello,

I have a radasyncupload control on my form for file uploads and have the PostBackTriggers property set to a button on the form for submitting the information.  The button also performs some server side validation and eventually performs some tasks based on successful validation.  The problem I have having is two fold:

1. When I click the button to submit my form, half of my code does not end up executing because the FileUploaded event fires.
2. If server side validation does complete prior and is not valid, the FileUpload still completes and the control is blank again causing the need to upload the file again.

What can I do to prevent this type of behavior?  More so I really need to get problem #1 fixed but I can't seem to find a way to be sure all code fires in the proper order.  Is there a way to call the FileUploaded event server side versus specifying the PostBackTriggers in the markup?  This way I can ensure all my code executes in the proper order and also completes.

Thanks,
Ron

2 Answers, 1 is accepted

Sort by
0
Accepted
Hristo Valyavicharski
Telerik team
answered on 30 Jan 2014, 01:23 PM
Hi Ron,

First the first problem try to remove the FileUploaded event and save all files from the Uploaded Files collection:
<telerik:RadAsyncUpload
    ID="asyncUpload"
    PostbackTriggers="btUpload"
    runat="server">
</telerik:RadAsyncUpload>
<asp:Button ID="btUpload" runat="server" Text="Upload" OnClick="btUpload_Click" />

protected void btUpload_Click(object sender, EventArgs e)
{
    foreach (UploadedFile file in asyncUpload.UploadedFiles)
    {
        ...
    }
}

Regarding the second question. You will have to use a Client Side validation. There is no way to persist the selected file if the server validation fails and the postback was caused by a control defined in the PostBackTriggers property.

Regards,
Hristo Valyavicharski
Telerik
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 UI for ASP.NET AJAX, subscribe to the blog feed now.
0
Ron
Top achievements
Rank 2
answered on 14 Feb 2014, 07:26 PM
Thank you Hristo, this was not the fix but it did help me find where the issue was.  Turns out it was not the upload control but there was an SQL statement bringing back the wrong information causing it to skip everything but actually saving the file uploaded as a new name to another location.  Because the file upload event is what I was using, the code for it always executed making me think it causing the other code to not execute.  Once I moved the code to a different subroutine I noticed it was no longer working and was able to pinpoint that SQL statement.
Tags
AsyncUpload
Asked by
Ron
Top achievements
Rank 2
Answers by
Hristo Valyavicharski
Telerik team
Ron
Top achievements
Rank 2
Share this question
or