Hi all,
The next code adds well known mechanism of preventing page leave to the "Simple Upload (Customizing the UI)" demo (with slight modifications):
- <%@ Page Language="C#" %>
-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
- <script runat="server">
- void InsertMsg(string msg)
- {
- ListBoxEvents.Items.Insert(0, msg);
- ListBoxEvents.SelectedIndex = 0;
- }
- void Uploader_FileUploaded(object sender, UploaderEventArgs args)
- {
- Uploader uploader = (Uploader)sender;
- InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");
-
- //Copys the uploaded file to a new location.
- //args.CopyTo("c:\\temp\\"+args.FileName);
- //You can also open the uploaded file's data stream.
- //System.IO.Stream data = args.OpenStream();
- }
-
- protected void Uploader1_UploadCompleted(object sender, UploaderEventArgs[] args)
- {
-
- }
- </script>
-
- <script type="text/javascript">
-
- window.onbeforeunload = confirmExit;
-
- function confirmExit() {
- return "Test!!!";
- }
-
- </script>
-
-
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>Simple Upload</title>
- <link rel="stylesheet" href="demo.css" type="text/css" />
- </head>
- <body>
- <form id="form1" runat="server">
- <div class="content">
- <h2>
- Simple Upload (Customizing the UI)
- </h2>
- <a href="http://www.dapasoft.com">Link</a>
- <p>
- A sample demonstrating how to customize the look and feel of file upload controls.
- (Maximum file size: 10M).
- </p>
- <asp:Image runat="server" ID="Uploader1Insert" AlternateText="Upload File" ImageUrl="~/sampleimages/upload.png" />
- <asp:Panel runat="server" ID="Uploader1Progress" BorderColor="Orange" BorderStyle="dashed"
- BorderWidth="2" Style="padding-right: 4px; padding-left: 4px; padding-bottom: 4px;
- padding-top: 4px">
- <asp:Label ID="Uploader1ProgressText" runat="server" ForeColor="Firebrick"></asp:Label>
- </asp:Panel>
- <asp:Image runat="server" ID="Uploader1Cancel" AlternateText="Cancel" ImageUrl="~/sampleimages/cancel_button.gif" />
- <CuteWebUI:Uploader runat="server" ID="Uploader1" InsertButtonID='Uploader1Insert'
- ProgressCtrlID='Uploader1Progress' ProgressTextID='Uploader1ProgressText' CancelButtonID='Uploader1Cancel'
- OnFileUploaded="Uploader_FileUploaded"
- onuploadcompleted="Uploader1_UploadCompleted">
- <ValidateOption MaxSizeKB="2097000" />
- </CuteWebUI:Uploader>
- <br />
- <br />
- <div>
- Server Trace:
- <br>
- <br>
- <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>
- </div>
- </div>
- </form>
- </body>
- </html>
If during file upload you try to leave the page next error appears:
Can be done something about it?
Regards,
Michael Raizman