FileValidated vs. FileUploaded events

Last post 11-11-2009, 8:23 PM by cutechat. 3 replies.
Sort Posts: Previous Next
  •  11-05-2009, 10:16 PM 56936

    FileValidated vs. FileUploaded events

    Hi there,
    I am uploading and resizing images using Ajax Uploader, based on the sample "Framework 2.0-VB"
    In order to resize the images between image uploads, as opposed to after all images have been uploaded, I moved the resizing code from the FileUploaded event to the  FileValidated event. I now find that
    1) the FileUploaded event is not hit, and 2) the ListBox displays no items after the page has run, even though the code in InsertMsg sub is executed. If I run the resizing code in the FileUploaded  events, the listbox displays the items.
    How can I get the listbox to display items?
    Thanks in advance,
    Rob Nagel
  •  11-08-2009, 7:45 PM 56964 in reply to 56936

    Re: FileValidated vs. FileUploaded events

    Rob Nagel ,
     
    the order of the events are :
     
    client side select multiple files
    client show file1 uploading
    server fire FileValidating event
    client show file1 finish
    client show file2 uploading
    server fire FileValidating event
    client show file2 finish
    ...
    client side fire Postback event
    server side fire FileUploaded event for each file
    server side fire UploadCompleted event
     
    If you move/delete the temp file in FileValiding event, the FileUploaded of that file will not fire.
     
    So you can resize the image , but please keep the filepath , and then move it in FileUploaded event.
     
    Regards,
    Terry
     
     
  •  11-09-2009, 12:44 AM 56969 in reply to 56964

    Re: FileValidated vs. FileUploaded events

    Thanks Terry,
     
    That worked  to get the FileUploaded event to fire.
     
    I still have a problem getting items to display in the Listbox, when these are initiated outside the  FileUploaded event. For example, I would like to put info for the user into the listbox regarding success/failure of the resize. Any items added to the listbox in the FileValidated event, or a function called by it, where the resize takes place, are not written to the listbox.
     
    Any pointers on how to achieve this?
     
    Thanks in advance
     
    Rob 
  •  11-11-2009, 8:23 PM 57070 in reply to 56969

    Re: FileValidated vs. FileUploaded events

    Rob,
     
    You can't update the server UI at the FileValidating event.
     
    Uploader provide a method to let you send some data to cient side, and then update the UI via JavaScript
     
    Please check this sample:
     
     
    1. <%@ Page Language="C#" %>  
    2.   
    3. <%@ Import Namespace="CuteWebUI" %>  
    4. <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" %>  
    5. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    6.   
    7. <script runat="server">  
    8.   
    9.     protected void UploadAttachments1_FileValidating(object sender, UploaderEventArgs args)   
    10.     {   
    11.         //you can send some data or message to client side   
    12.         UploadAttachments1.SetValidationServerData("File validated at " + DateTime.Now.ToString("HH:mm:ss"));   
    13.   
    14.         //updating the UI has no effect!   
    15.         labelMsg.Text = "Validated!";   
    16.     }   
    17.   
    18.     protected void UploadAttachments1_FileUploaded(object sender, UploaderEventArgs args)   
    19.     {   
    20.            
    21.     }   
    22. </script>  
    23.   
    24. <html xmlns="http://www.w3.org/1999/xhtml">  
    25. <head id="Head1" runat="server">  
    26.     <title>Untitled Page</title>  
    27. </head>  
    28. <body>  
    29.     <form id="form1" runat="server">  
    30.         <div>  
    31.             <CuteWebUI:UploadAttachments runat="server" ID="UploadAttachments1" InsertText="Add files" OnFileValidating="UploadAttachments1_FileValidating" OnFileUploaded="UploadAttachments1_FileUploaded">  
    32.             </CuteWebUI:UploadAttachments>  
    33.             <br />  
    34.             <asp:Label runat="server" ID="labelMsg" />  
    35.         </div>  
    36.     </form>  
    37. </body>  
    38.   
    39. <script type="text/javascript">  
    40. function CuteWebUI_AjaxUploader_OnTaskComplete(file)   
    41. {   
    42.     //You can get the custom data here , (or using uploader.getitems()[i].ServerData)   
    43.     alert(file.ServerData);   
    44. }   
    45. </script>  
    46.   
    47. </html>  
     
    Regards,
    Terry
     
     
View as RSS news feed in XML