FileUploaded Causing Issues

3 posts, 1 answers
  1. Ron
    Ron avatar
    86 posts
    Member since:
    Sep 2009

    Posted 27 Jan 2014 Link to this post


    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.

  2. Answer
    Hristo Valyavicharski
    Hristo Valyavicharski avatar
    975 posts

    Posted 30 Jan 2014 Link to this post

    Hi Ron,

    First the first problem try to remove the FileUploaded event and save all files from the Uploaded Files collection:
    <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.

    Hristo Valyavicharski
    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.
  3. Ron
    Ron avatar
    86 posts
    Member since:
    Sep 2009

    Posted 14 Feb 2014 in reply to Hristo Valyavicharski Link to this post

    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.
Back to Top