Leave page mechanism during upload.

Last post 11-24-2009, 10:04 AM by cutechat. 3 replies.
Sort Posts: Previous Next
  •  11-17-2009, 3:29 PM 57222

    Leave page mechanism during upload.

    Hi all,
     
    The next code adds well known mechanism of preventing page leave to the "Simple Upload (Customizing the UI)" demo (with slight modifications):
    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.     void InsertMsg(string msg)  
    7.     {  
    8.         ListBoxEvents.Items.Insert(0, msg);  
    9.         ListBoxEvents.SelectedIndex = 0;  
    10.     }  
    11.     void Uploader_FileUploaded(object sender, UploaderEventArgs args)  
    12.     {  
    13.         Uploader uploader = (Uploader)sender;  
    14.         InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");  
    15.   
    16.         //Copys the uploaded file to a new location.  
    17.         //args.CopyTo("c:\\temp\\"+args.FileName);  
    18.         //You can also open the uploaded file's data stream.  
    19.         //System.IO.Stream data = args.OpenStream();  
    20.     }  
    21.   
    22.     protected void Uploader1_UploadCompleted(object sender, UploaderEventArgs[] args)  
    23.     {  
    24.   
    25.     }  
    26. </script>  
    27.   
    28. <script type="text/javascript">  
    29.   
    30. window.onbeforeunload = confirmExit;  
    31.   
    32. function confirmExit() {  
    33.     return "Test!!!";  
    34. }  
    35.   
    36. </script>  
    37.   
    38.   
    39. <html xmlns="http://www.w3.org/1999/xhtml">  
    40. <head runat="server">  
    41.     <title>Simple Upload</title>  
    42.     <link rel="stylesheet" href="demo.css" type="text/css" />  
    43. </head>  
    44. <body>  
    45.     <form id="form1" runat="server">  
    46.         <div class="content">  
    47.             <h2>  
    48.                 Simple Upload (Customizing the UI)  
    49.             </h2>  
    50.             <a href="http://www.dapasoft.com">Link</a>  
    51.             <p>  
    52.                 A sample demonstrating how to customize the look and feel of file upload controls.  
    53.                 (Maximum file size: 10M).  
    54.             </p>  
    55.             <asp:Image runat="server" ID="Uploader1Insert" AlternateText="Upload File" ImageUrl="~/sampleimages/upload.png" />  
    56.             <asp:Panel runat="server" ID="Uploader1Progress" BorderColor="Orange" BorderStyle="dashed"  
    57.                 BorderWidth="2" Style="padding-right: 4px; padding-left: 4px; padding-bottom: 4px;  
    58.                 padding-top: 4px">  
    59.                 <asp:Label ID="Uploader1ProgressText" runat="server" ForeColor="Firebrick"></asp:Label>  
    60.             </asp:Panel>  
    61.             <asp:Image runat="server" ID="Uploader1Cancel" AlternateText="Cancel" ImageUrl="~/sampleimages/cancel_button.gif" />  
    62.             <CuteWebUI:Uploader runat="server" ID="Uploader1" InsertButtonID='Uploader1Insert'  
    63.                 ProgressCtrlID='Uploader1Progress' ProgressTextID='Uploader1ProgressText' CancelButtonID='Uploader1Cancel'  
    64.                 OnFileUploaded="Uploader_FileUploaded"   
    65.                 onuploadcompleted="Uploader1_UploadCompleted">  
    66.                 <ValidateOption MaxSizeKB="2097000" />  
    67.             </CuteWebUI:Uploader>  
    68.             <br />  
    69.             <br />  
    70.             <div>  
    71.                 Server Trace:  
    72.                 <br>  
    73.                 <br>  
    74.                 <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>  
    75.             </div>  
    76.         </div>  
    77.     </form>  
    78. </body>  
    79. </html> 
     
     
    If during file upload you try to leave the page next error appears:
     
    Can be done something about it?

    Regards,
    Michael Raizman
  •  11-18-2009, 10:32 AM 57256 in reply to 57222

    Re: Leave page mechanism during upload.

    Hi,
     
    Currently you can get avoid of the message by this way :
     
    <script>
    function CuteWebUI_AjaxUploader_OnError(msg)
    {
          if(msg.indexOf("transfer expired")!=-1)
                   return true;
    }
    </script>
     
    Regards,
    Terry
  •  11-18-2009, 1:30 PM 57261 in reply to 57256

    Re: Leave page mechanism during upload.

    Hi Terry,
     
    Thank you for your answer.

    If I press "Back" button, it doesn't help, I still see the error message.

    Regards,
    Michael Raizman
  •  11-24-2009, 10:04 AM 57387 in reply to 57261

    Re: Leave page mechanism during upload.

    Michael ,
     
    I have checked it.
     
    We will find another solution and will provide an update soon.
     
    Regards,
    Terry
     
View as RSS news feed in XML