Multiple fileupload in usercontrol. When submitting, AttachmentItemCollection does not have any items (count = 0)

Last post 02-27-2014, 8:07 AM by Kenneth. 3 replies.
Sort Posts: Previous Next
  •  02-26-2014, 7:18 AM 79974

    Multiple fileupload in usercontrol. When submitting, AttachmentItemCollection does not have any items (count = 0)

     Greetings.. and thanks for reading my post.

     

    Using the control more or less "out of the box" in the manual upload files example. Only difference from official example and mine, is that i'm using it in a usercontrol context.

     

    Everything seems to work fine  (lists out items to be uploaded etc.etc.) but when pressing "Submit" the "AttachmentItemCollection" doesn't have any items inside.. Not sure if it's the usercontrol or what but here is the structure of the page :

     

    So to summarize : CuteWebUi.AttachmentItemCollection.Count = 0 even though items are listed out in the listbox for "to-be-processed".

     

    Anyone have any ideas on this ? 


    <asp:UpdatePanel runat="server" UpdateMode="Conditional">
                    <Triggers>
                        <asp:PostBackTrigger ControlID="lnkUploadDocument" />
                        <asp:PostBackTrigger ControlID="lnkCancel" />
                        <asp:PostBackTrigger ControlID="LnkForsideDokument" />
                    </Triggers>
                    <ContentTemplate>
    <asp:Panel runat="server" ID="pnlUploadCtrl">                            

    <table class="upload-document-table">
                                    <tr>
                                        <td class="td-text">Last opp dokument</td>
                                        <td>
                                            <CuteWebUI:UploadAttachments runat="server" ManualStartUpload="true" ID="Uploader1"
                                                InsertText="Bla gjennom filer" OnFileUploaded="Uploader_FileUploaded">
                                                <ValidateOption MaxSizeKB="1024" />
                                            </CuteWebUI:UploadAttachments>
                                            <p>
                                                <asp:Button runat="server" ID="SubmitButton" Text="Last opp" OnClick="SubmitButton_Click" />
                                            </p>
                                            <p>
                                                <asp:ListBox runat="server" ID="ListBoxEvents" />
                                            </p>
                                            <%--<asp:FileUpload runat="server" ID="fuplDocument" />--%>
                                        </td>
                                    </tr>
                                </table>
                            </asp:Panel>

     </ContentTemplate>

    </asp:UpdatePanel>

     

    Here are the back-end methods : 

     

    void InsertMsg(string msg)        {            ListBoxEvents.Items.Insert(0, msg);            ListBoxEvents.SelectedIndex = 0;        }
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                SubmitButton.Attributes["onclick"] = "return submitbutton_click()";
            }

            protected void SubmitButton_Click(object sender, EventArgs e)
            {

                InsertMsg("You clicked the Submit Button.");
                InsertMsg("You have uploaded " + uploadcount + "/" + Uploader1.Items.Count + " files.");
            }

            int uploadcount = 0;

            protected override void OnPreRender(EventArgs e)
            {
                SubmitButton.Attributes["itemcount"] = Uploader1.Items.Count.ToString();

                base.OnPreRender(e);
            }


     protected void Uploader_FileUploaded(object sender, UploaderEventArgs args)        {            uploadcount++;            InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");

                //Copys the uploaded file to a new location.
                //args.CopyTo(path);
                //You can also open the uploaded file's data stream.
                //System.IO.Stream data = args.OpenStream();
            }
        }
  •  02-26-2014, 8:11 AM 79975 in reply to 79974

    Re: Multiple fileupload in usercontrol. When submitting, AttachmentItemCollection does not have any items (count = 0)

    Hi nygter,

     

    What you are using is the  ManualStartUpload upload mode, but I did not saw the start upload code in the code you provided. The AttachmentItemCollection items only available after upload successful not after selected the files for upload.

     

    Regards,

     

    Ken 

  •  02-26-2014, 12:29 PM 79981 in reply to 79975

    Re: Multiple fileupload in usercontrol. When submitting, AttachmentItemCollection does not have any items (count = 0)

     Hmm.. so i have misunderstood something here ?

     

    The only thing i want is picking the files, and then upload  them with a submit button.

     

    is'nt that what my code does ? ;)

     

    If not.. can you give me a code-correction ?

     

    Terje :)

  •  02-27-2014, 8:07 AM 79987 in reply to 79981

    Re: Multiple fileupload in usercontrol. When submitting, AttachmentItemCollection does not have any items (count = 0)

    Hi nygter,

     

    Below is the javascript part of the start upload manually example, it use to start the upload when click on the button.  If you do not use the js code to start the upload, then when click on the button, it will not does anything.

     

    1. <script type="text/javascript">  
    2.            function submitbutton_click() {  
    3.                var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');  
    4.                var uploadobj = document.getElementById('<%=Uploader1.ClientID %>');  
    5.                if (uploadobj.getqueuecount() == 0) {  
    6.                    submitbutton.click();  
    7.                } else {  
    8.                    if (!window.filesuploaded) {  
    9.                        if (uploadobj.getqueuecount() > 0) {  
    10.                            uploadobj.startupload();  
    11.                        }  
    12.                        return false;  
    13.                    }  
    14.                }  
    15.                window.filesuploaded = false;  
    16.                return true;  
    17.            }  
    18.            function CuteWebUI_AjaxUploader_OnPostback() {  
    19.                window.filesuploaded = true;  
    20.                var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');  
    21.       submitbutton.click();  
    22.       return false;  
    23.   }  
    24.        </script>  
     

    Regards,

     

    Ken 

View as RSS news feed in XML