execute code when no items to be uploaded

Last post 02-29-2012, 8:17 AM by Anonymous. 2 replies.
Sort Posts: Previous Next
  •  02-29-2012, 5:49 AM 73253

    execute code when no items to be uploaded

    Hi
     
    I have the ajaxuploadaattachments control added to a page.
    I start the upload manually on button Save Click
    But when no items are selected in the uploader the code behind the button will not fire.
    When I do select itemsto be uploaded the code behind will fire.
     
    aspx code:
     
    1. <script type="text/javascript">  
    2.   
    3.     function submitbutton_click() {  
    4.         var submitbutton = document.getElementById('<%=btnSave.ClientID %>');  
    5.         var uploadimg = document.getElementById('<%=uplFiles.ClientID %>');  
    6.         if (!window.filesuploaded) {  
    7.             if (uploadimg.getqueuecount() > 0) {  
    8.                 uploadimg.startupload();  
    9.             }  
    10.             else {  
    11.                   
    12.                 submitbutton.click();  
    13.             }  
    14.             return false;  
    15.         }  
    16.         window.filesuploaded = false;  
    17.         return true;  
    18.     }  
    19.   
    20.     function CuteWebUI_AjaxUploader_OnError(msg) {  
    21.         alert("Algemene fout:" + msg);  
    22.         return false;  
    23.     }  
    24.     function CuteWebUI_AjaxUploader_OnTaskError(obj, msg, reason) {  
    25.         alert("Bestandfout:" + obj.FileName + " , " + msg);  
    26.         return false;  
    27.     }  
    28.   
    29.     function CuteWebUI_AjaxUploader_OnPostback() {  
    30.         window.filesuploaded = true;  
    31.         var submitbutton = document.getElementById('<%=btnSave.ClientID %>');  
    32.         submitbutton.click();  
    33.         return false;  
    34.     }  
    35.         </script>  
    The button code:
     
    1. <asp:Button runat="server" ID="btnSave" Text="Wijzigen" OnClick="btnSave_Click"  OnClientClick="return submitbutton_click()" />  
    The control code:
     
    1. <cc2:UploadAttachments ID="uplFiles" runat="server" ManualStartUpload="true"  
    2.                                 MaxFilesLimit="5" FileTooLargeMsg="Bestand is te groot! Max. 5 MB."  
    3.                                 MultipleFilesUpload="true" ShowProgressInfo="false" ShowProgressBar="false" InsertText="Kies uw bestanden"  
    4.                                 MaxFilesLimitMsg="U mag maximaal 5 bestanden uploaden" RemoveButtonText="Verwijder" ShowTableHeader="false"  
    5.                                 ShowFileIcons="true" CancelAllMsg="Verwijder alles">  
    6.                                 <ValidateOption MaxSizeKB="5120" AllowedFileExtensions="pdf,doc,docx,xls,xls,rtf,txt" />  
    7.                             </cc2:UploadAttachments>  
    Please help.  
  •  02-29-2012, 7:59 AM 73255 in reply to 73253

    Re: execute code when no items to be uploaded

    Hi dbots,
     
    Please try the example page below, the submit button will fire every time.
     
    <%@ Page Language="C#" %>
    <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">   
     
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            label1.Text = "submit button clicked!";
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Start uploading manually</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <asp:Label ID="label1" runat="server"></asp:Label><br />
            <CuteWebUI:UploadAttachments ID="Uploader1" runat="server" ManualStartUpload="true">
            </CuteWebUI:UploadAttachments>
            <br />
            <br />
            <asp:Button runat="server" ID="SubmitButton" OnClientClick="return submitbutton_click()"
                Text="Submit" OnClick="SubmitButton_Click" /><br />
            <script type="text/javascript">
       function submitbutton_click() {
           var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');
           var uploadobj = document.getElementById('<%=Uploader1.ClientID %>');
           if (uploadobj.getqueuecount() == 0) {
               submitbutton.click();
           } else {
               if (!window.filesuploaded) {
                   if (uploadobj.getqueuecount() > 0) {
                       uploadobj.startupload();
                   }
                   return false;
               }
           }
           window.filesuploaded = false;
           return true;
       }
       function CuteWebUI_AjaxUploader_OnPostback() {
           window.filesuploaded = true;
           var submitbutton = document.getElementById('<%=SubmitButton.ClientID %>');
           submitbutton.click();
           return false;
       }
            </script>
        </form>
    </body>
    </html>
     
    Regards,
     
    Ken 
  •  02-29-2012, 8:17 AM 73257 in reply to 73255

    Re: execute code when no items to be uploaded

    works. thanx
View as RSS news feed in XML