OnAttachmentAdded when using ManualStartUpload

Last post 09-14-2010, 12:34 AM by Kenneth. 3 replies.
Sort Posts: Previous Next
  •  09-07-2010, 6:22 PM 63870

    OnAttachmentAdded when using ManualStartUpload

    The site I'm developing requires that the user manually specifies the total number of files they're submitting for later comparison with the total number of files they've uploaded...mostly as a precaution against forgotten files.  My goal is to generate a dynamic file count as items are added so that I can compare the two counts prior to upload using Javascript. 
     
    I'm using the AjaxUploaded with the ManualStartUpload flag set but the OnAttachmentAdded event doesn't seem to fire and I'm assuming its because of the ManualStartUpload.  Is there a way to get the file count as items are added when usng the ManualStartUpload flag?
     
    <CuteWebUI:UploadAttachments ID="objUploader" runat="server" ManualStartUpload="true" MultipleFilesUpload="true" InsertButtonID="btnAddFile" OnUploadCompleted="UploadCompleted" OnAttachmentAdded="AttachmentAdded" >

    <
    script runat="server">
       Protected Sub AttachmentAdded(ByVal sender As Object, ByVal args As CuteWebUI.AttachmentItemEventArgs)
          lblNumberFilesAdded.Text = objUploader.Items.Count.ToString   
       End Sub
    </script>
     
    Thanks for your help.
     
    -Sean
  •  09-07-2010, 9:47 PM 63874 in reply to 63870

    Re: OnAttachmentAdded when using ManualStartUpload

    Hi skruis,
     
    Please try the example below
     
    1. <%@ Page Language="VB" %>   
    2.   
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
    4.   
    5. <script runat="server">   
    6.     Private uploadcount As Integer = 0   
    7.     Protected Overrides Sub OnPreRender(ByVal e As EventArgs)   
    8.         SubmitButton.Attributes("itemcount") = Uploader1.Items.Count.ToString()   
    9.   
    10.         MyBase.OnPreRender(e)   
    11.     End Sub  
    12.   
    13. </script>   
    14.   
    15. <html xmlns="http://www.w3.org/1999/xhtml">   
    16. <head runat="server">   
    17.     <title>Untitled Page</title>   
    18. </head>   
    19. <body>   
    20.     <form id="form1" runat="server">   
    21.         <CuteWebUI:UploadAttachments runat="server" ManualStartUpload="true" ID="Uploader1"  
    22.             InsertText="Browse Files ">   
    23.         </CuteWebUI:UploadAttachments>   
    24.         <br />   
    25.         <br />   
    26.         <asp:Button runat="server" ID="SubmitButton" OnClientClick="return submitbutton_click()"  
    27.             Text="Submit" /><br />   
    28.         <br />   
    29.         <input type="button" value="get count" onclick="getCount()" />   
    30.     </form>   
    31. </body>   
    32. </html>   
    33.   
    34. <script type="text/javascript">   
    35.     function getCount()   
    36.     {   
    37.     var uploadobj=document.getElementById('<%=Uploader1.ClientID %>');   
    38.         alert(uploadobj.getqueuecount());   
    39.     }   
    40.     function submitbutton_click()   
    41.     {   
    42.         var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');   
    43.         var uploadobj=document.getElementById('<%=Uploader1.ClientID %>');   
    44.         if(!window.filesuploaded)   
    45.         {   
    46.             if(uploadobj.getqueuecount()>0)   
    47.             {   
    48.                 uploadobj.startupload();   
    49.             }   
    50.             else   
    51.             {   
    52.                 var uploadedcount=parseInt(submitbutton.getAttribute("itemcount"))||0;   
    53.                 if(uploadedcount>0)   
    54.                 {   
    55.                     return true;   
    56.                 }   
    57.                 alert("Please browse files for upload");   
    58.             }   
    59.             return false;   
    60.         }   
    61.         window.filesuploaded=false;   
    62.         return true;   
    63.     }   
    64.     function CuteWebUI_AjaxUploader_OnPostback()   
    65.     {   
    66.         window.filesuploaded=true;   
    67.         var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');   
    68.         submitbutton.click();   
    69.         return false;   
    70.     }   
    71. </script>  
    Regards,
     
    ken
  •  09-11-2010, 2:48 PM 63938 in reply to 63874

    Re: OnAttachmentAdded when using ManualStartUpload

    I was able to modify your suggestion.  The key part which I was missing but already had already used somewhere in my page was the "uploadobj.getqueuecount" method.  I was able to modify my existing validation function using that method and its working perfectly now.  Out of curiosity, is there a javascript event I can handle when the queue count is modified?
     
    Thanks,
     
    Sean
  •  09-14-2010, 12:34 AM 63973 in reply to 63938

    Re: OnAttachmentAdded when using ManualStartUpload

    Hi skruis,

    Please try the new example

     

    1. <%@ Page Language="VB" %>      
    2.      
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">      
    4.      
    5. <script runat="server">      
    6.     Private uploadcount As Integer = 0      
    7.     Protected Overrides Sub OnPreRender(ByVal e As EventArgs)      
    8.         SubmitButton.Attributes("itemcount") = Uploader1.Items.Count.ToString()      
    9.      
    10.         MyBase.OnPreRender(e)      
    11.     End Sub     
    12.      
    13. </script>      
    14.      
    15. <html xmlns="http://www.w3.org/1999/xhtml">      
    16. <head id="Head1" runat="server">      
    17.     <title>Untitled Page</title>      
    18. </head>      
    19. <body>      
    20.     <form id="form1" runat="server">      
    21.         <CuteWebUI:UploadAttachments runat="server" ManualStartUpload="true" ID="Uploader1"     
    22.             InsertText="Browse Files ">      
    23.         </CuteWebUI:UploadAttachments>      
    24.         <br />      
    25.         <br />      
    26.         <asp:Button runat="server" ID="SubmitButton" OnClientClick="return submitbutton_click()"     
    27.             Text="Submit" /><br />      
    28.         <br />      
    29.         <input type="button" value="get count" onclick="getCount()" />      
    30.     </form>      
    31. </body>      
    32. </html>      
    33.      
    34. <script type="text/javascript">      
    35.     function getCount()      
    36.     {      
    37.     var uploadobj=document.getElementById('<%=Uploader1.ClientID %>');      
    38.         alert(uploadobj.getqueuecount());      
    39.     }      
    40.     function submitbutton_click()      
    41.     {      
    42.         var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');      
    43.         var uploadobj=document.getElementById('<%=Uploader1.ClientID %>');      
    44.         if(!window.filesuploaded)      
    45.         {      
    46.             if(uploadobj.getqueuecount()>0)      
    47.             {      
    48.                 uploadobj.startupload();      
    49.             }      
    50.             else      
    51.             {      
    52.                 var uploadedcount=parseInt(submitbutton.getAttribute("itemcount"))||0;      
    53.                 if(uploadedcount>0)      
    54.                 {      
    55.                     return true;      
    56.                 }      
    57.                 alert("Please browse files for upload");      
    58.             }      
    59.             return false;      
    60.         }      
    61.         window.filesuploaded=false;      
    62.         return true;      
    63.     }      
    64.     function CuteWebUI_AjaxUploader_OnPostback()      
    65.     {      
    66.         window.filesuploaded=true;      
    67.         var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');      
    68.         submitbutton.click();      
    69.         return false;      
    70.     }      
    71. function CuteWebUI_AjaxUploader_OnQueueUI(list)   
    72.   
    73. {   
    74.     //Will be triggered when the value changes   
    75.     alert("count change,current : "+list.length);   
    76. }   
    77.   
    78.   
    79. </script>    
    Regards,
    ken

     

     

View as RSS news feed in XML