UploadCompleted firing before all files are uploaded

  •  01-22-2012, 5:12 PM

    UploadCompleted firing before all files are uploaded

    HI,
          The UploadCompleted appers to be firing before all files have completed uploading.
         I have the UploadAttachments  in an update panel say UP1  and another update panel say UP2 with dropdowns, textboxes etc some of which cause a postback.  Both UP1 and UP2 are set to conditional.
           A postback in UP2 is causing the UploadCompleted to fire if at least one file has been uploaded even though the upload is in progress.
     
    Part of my code is pasted below.
    If while the upload is going on (and after at least one file has been uplaoded)- you click the button which says Click Me - the control will jump to UploadCompleted and set the hidden variable to C.
     
    Can you please tell me what I am doing wrong? I am trying to have the file upload go on in an update panel while the user continues to fill in data in the second update panel. And I need to capture which completed first so I do need the UploadComplete to file ONLY after the file uploads are all completed.
     
    Can you provide me an alternate solution?
     

     

     

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"

     

    CodeBehind="Default.aspx.cs" Inherits="LibraryUI.Web._Default" %>

     

     

     

    <script runat="server">

     

     

    protected void SubmitButton_Click(object sender, EventArgs e)

    {

    hdnFileUploadComplete.Value = "S"; //file upload started

     

    Uploader1.InsertButton.Enabled = false;

    Uploader1.CancelButton.Enabled = false;

    SubmitButton.Enabled = false;

    UpnlFileUpload.Update();

    }

     

    protected void Uploader1_UploadCompleted(object sender, UploaderEventArgs[] args)

    {

    hdnFileUploadComplete.Value = "C"; //file upload completed first

     

    UpnlFileUpload.Update();

    }

     

    </script>

     

    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">

     

     

     

    </asp:Content>

     

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

     

    <div style="float:right;padding-right:50px;" >

    <asp:HyperLink id="hlEdit" runat="server" CssClass="SiteLinkLarger" Text="Help" NavigateUrl="About.aspx"></asp:HyperLink>

    </div>

     

    <asp:UpdatePanel runat="server" ID="UpnlFileUpload" UpdateMode="Conditional" RenderMode="Block">

    <ContentTemplate>

    <asp:Panel ID="PnlFileUpload" runat="server" style="display:block" >

     

    <p> Select File(s) to be published : Max total file size allowed is 2 GB </p>

    <CuteWebUI:UploadAttachments runat="server" MultipleFilesUpload="true" ManualStartUpload="true" ID="Uploader1" MaxFilesLimit="50" InsertText="Browse Files"

    OnUploadCompleted="Uploader1_UploadCompleted" >

     

     

     

    </CuteWebUI:UploadAttachments>

     

    <br />

    <br />

     

    <asp:HiddenField id ="hdnFileUploadComplete" runat="server" />

    <br />

     

    <asp:Button runat="server" ID="SubmitButton" OnClientClick="return submitbutton_click()"

     

    Text="Done Selecting File(s)" OnClick="SubmitButton_Click" CausesValidation="false" />

     

     

     

    <asp:Button ID="btnCancelPublish" runat="server" text="Cancel All" OnClientClick="return cancelalltasks();" CausesValidation="false" Enabled="false"></asp:Button>

     

     

    <br /><br />

     

    </asp:Panel>

     

     

    </ContentTemplate>

     

    </asp:UpdatePanel>

     

    <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional" RenderMode="Block">

    <ContentTemplate>

     

    <asp:Button ID="Button1" runat="server" Text="Click Me"/>

    </ContentTemplate>

     

    </asp:UpdatePanel>

     

     

     

    <script type="text/javascript">

     

    var filelist;

     

    function submitbutton_click() {

     

    var uploadobj = document.getElementById('<%=Uploader1.ClientID %>');

     

    if (!window.filesuploaded)

    {

     

    if (uploadobj.getqueuecount() > 0) {

    uploadobj.startupload();

     

    }

     

    if (uploadobj.getqueuecount() == 0) {

    alert("Please browse files for upload");

     

    return false;

    }

    }

    window.filesuploaded = false;

     

    return true;

    }

     

     

     

    function CuteWebUI_AjaxUploader_OnPostback() {

    window.filesuploaded = true;

     

    var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');

    submitbutton.click();

     

    return false;

    }

     

    function CuteWebUI_AjaxUploader_OnInitialize() {

    window.filesuploaded = false;

    }

     

    function cancelalltasks() {

    var uploadobj = document.getElementById('<%=Uploader1.ClientID %>');

    if (confirm("Are you sure you want to cancel?")) {

    uploadobj.cancelall();

    window.location.reload();

    return true;

    }

    else return false;

    }

     

    </script>

     

    </asp:Content>

     

View Complete Thread