Manually upload

Last post 05-05-2009, 2:05 PM by cutechat. 3 replies.
Sort Posts: Previous Next
  •  04-29-2009, 1:47 PM 51671

    Manually upload

    HI,
    I'm trying to use the manually upload option. I've copied the javascript function from "Start-uploading-manually.aspx" file comming with the control but I have a problem.
    When I use the script as is, the submit button click event (server side) is firing before the FileUploaded event of the control. If I set the return value of the script to false then the FileUploaded event s fired but the submit click event is not.
  •  04-29-2009, 2:02 PM 51672 in reply to 51671

    Re: Manually upload

    Can you try the following example?
     
    1. <%@ Page Language="C#" %>  
    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.        
    7.     void InsertMsg(string msg)   
    8.     {   
    9.         ListBoxEvents.Items.Insert(0, msg);   
    10.         ListBoxEvents.SelectedIndex = 0;   
    11.     }   
    12.   
    13.     protected override void OnInit(EventArgs e)   
    14.     {   
    15.         base.OnInit(e);   
    16.   
    17.         Uploader1.FileUploaded += new UploaderEventHandler(Uploader_FileUploaded);   
    18.         ButtonPostBack.Click += new EventHandler(ButtonPostBack_Click);   
    19.     }   
    20.   
    21.     void ButtonPostBack_Click(object sender, EventArgs e)   
    22.     {   
    23.         InsertMsg("You clicked a PostBack Button.");   
    24.     }   
    25.   
    26.     void SubmitButton_Click(object sender, EventArgs e)   
    27.     {   
    28.         InsertMsg("You clicked the Submit Button.");   
    29.         InsertMsg("You have uploaded "+uploadcount+"/"+Uploader1.Items.Count+" files.");   
    30.     }   
    31.   
    32.     int uploadcount = 0;   
    33.   
    34.     void Uploader_FileUploaded(object sender, UploaderEventArgs args)   
    35.     {   
    36.         uploadcount++;   
    37.            
    38.         Uploader uploader = (Uploader)sender;   
    39.         InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");   
    40.   
    41.         //Copys the uploaded file to a new location.   
    42.         //args.CopyTo(path);   
    43.         //You can also open the uploaded file's data stream.   
    44.         //System.IO.Stream data = args.OpenStream();   
    45.     }   
    46.   
    47.     protected override void OnPreRender(EventArgs e)   
    48.     {   
    49.         SubmitButton.Attributes["itemcount"] = Uploader1.Items.Count.ToString();   
    50.            
    51.         base.OnPreRender(e);   
    52.     }   
    53.        
    54. </script>  
    55.   
    56. <html xmlns="http://www.w3.org/1999/xhtml">  
    57. <head id="Head1" runat="server">  
    58.     <title> Start uploading manually</title>  
    59.     <link rel="stylesheet" href="demo.css" type="text/css" />  
    60. </head>  
    61. <body>  
    62.     <form id="form1" runat="server">  
    63.         <div class="content">  
    64.               
    65.        <h2>Start uploading manually</h2>  
    66.     <p> This sample demonstrates how to start uploading manually after file selection vs automatically.</p>  
    67.     <CuteWebUI:UploadAttachments runat="server" ManualStartUpload="true" ID="Uploader1"  
    68.         InsertText="Browse Files (Max 1M)" >  
    69.         <VALIDATEOPTION MaxSizeKB="1024" />  
    70.     </CuteWebUI:UploadAttachments>  
    71.        
    72.     <br />  
    73.     <br />  
    74.     <asp:Button runat="server" ID="SubmitButton" OnClientClick="return submitbutton_click()" Text="Submit" OnClick="SubmitButton_Click" />  
    75.     <br />  
    76.     <br />  
    77.     <div>  
    78.        
    79.         <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>  
    80.     </div>  
    81.     <br />  
    82.     <br />  
    83.     <asp:Button ID="ButtonPostBack" Text="This is a PostBack button" runat="server" />  
    84.        
    85.     <script type="text/javascript">  
    86.        
    87.     function submitbutton_click()   
    88.     {   
    89.         var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');   
    90.         var uploadobj=document.getElementById('<%=Uploader1.ClientID %>');   
    91.         if(!window.filesuploaded)   
    92.         {   
    93.             if(uploadobj.getqueuecount()>0)   
    94.             {   
    95.                 uploadobj.startupload();   
    96.             }   
    97.             else   
    98.             {   
    99.                 var uploadedcount=parseInt(submitbutton.getAttribute("itemcount"))||0;   
    100.                 if(uploadedcount>0)   
    101.                 {   
    102.                     return true;   
    103.                 }   
    104.                 alert("Please browse files for upload");   
    105.             }   
    106.             return false;   
    107.         }   
    108.         window.filesuploaded=false;   
    109.         return true;   
    110.     }   
    111.     function CuteWebUI_AjaxUploader_OnPostback()   
    112.     {   
    113.         window.filesuploaded=true;   
    114.         var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');   
    115.         submitbutton.click();   
    116.         return false;   
    117.     }   
    118.     </script>  
    119.        
    120.                 
    121.         </div>  
    122.     </form>  
    123. </body>  
    124. </html>  

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  04-30-2009, 10:38 AM 51698 in reply to 51672

    Re: Manually upload

    That is the code from the Start-uploading-manually.aspx file. Its the code I copied and used.
    BTW the items.count doesn't work also.
  •  05-05-2009, 2:05 PM 51834 in reply to 51698

    Re: Manually upload

    Hi,
     
    Sometimes the uploader is not able to get posted data before the button event. So the FileUploaded event will delay.
     
    For that issue , you can try to use OnPreRender event instead of the button onclick event..
     
    Regards,
    Terry
View as RSS news feed in XML