title: File Upload from Popup - Broken in IE9, Works Elsewhere
body: <p>We've used for some years a home-grown file uploader for our classic ASP website. It works like this:</p>
  
  <ol>
  <li>ASP page sets some specific constants and #includes an ASP library called Browse-Files.asp.</li>
  <li>Browse-Files.asp displays, inside the #including page, a file explorer-like view of the directories and files in a directory. It also shows various HTML links to allow file modification functions - create a directory, upload a file, move, rename and delete existing files.</li>
  <li>Each of these links calls a Javascript function that generates a simple HTML page in a popup window. These popups contain the required HTML form for the requested file modification activity. The HTML source for the popup pages is generated on the fly by Javascipt, rather than loading a static .htm or .asp file (this is purely so that all of the functionality of Browse-Files.asp is located in 1 file).</li>
  <li>The user fills in the popup form and submits. The form submits back to the parent page (form target attribute) and closes itself (Javascript timer, window.close).</li>
  <li>The parent page refreshes due to the form submit, showing the change the user requested.</li>
  </ol>
  
  <p>Issue is: this has worked fine for some years on various browsers, IE 6 to 8, Firefox and Opera. However, in IE9, the file upload does not work. The other popup-based tasks such as file renaming and directory creation continue to work.</p>
  
  <p>Code - the file rename popup (works in IE9 and all before):</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Rename&lt;/title&gt;
  &lt;link rel="stylesheet" href="/Common/CSS/screen.css" type="text/css" media="screen" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Rename&lt;/h1&gt;
  &lt;p&gt;Enter the new name for "Config Mgmt Text.txt" in the folder "General/Share-Files/":&lt;/p&gt;
  &lt;form name="form" method="post" action="/General/Share-Files.asp" encType="multipart/form-data" target="Browse-Files" onSubmit="self.setTimeout('window.close()', 500)"&gt;
  &lt;input name="task" type="hidden" value="T03" /&gt;
  &lt;input name="path" type="hidden" value="General/Share-Files/" /&gt;
  &lt;input name="target" type="hidden" value="Config Mgmt Text.txt" /&gt;
  &lt;input name="name" type="text" tabindex="1" size="40" value="Config Mgmt Text.txt"&gt;&lt;/input&gt;
  &lt;input name="submit" type="submit" value="Rename" tabindex="2" /&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Code - the file upload popup (broken in IE9, works in all before):</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Add Files&lt;/title&gt;
  &lt;link rel="stylesheet" href="/Common/CSS/screen.css" type="text/css" media="screen" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h1&gt;Add Files&lt;/h1&gt;
  &lt;p&gt;Browse for files to add to the folder "General/Share-Files/":&lt;/p&gt;
  &lt;form name="form" method="post" action="/General/Share-Files.asp" encType="multipart/form-data" target="Browse-Files" onSubmit="self.setTimeout('window.close()', 500)"&gt;
  &lt;input name="task" type="hidden" value="T01" /&gt;
  &lt;input name="path" type="hidden" value="General/Share-Files/" /&gt;
  &lt;input name="file1" type="file" tabindex="1" size="40"&gt;&lt;/input&gt;&lt;br /&gt;
  &lt;input name="file2" type="file" tabindex="2" size="40"&gt;&lt;/input&gt;&lt;br /&gt;
  &lt;input name="file3" type="file" tabindex="3" size="40"&gt;&lt;/input&gt;&lt;br /&gt;
  &lt;input name="file4" type="file" tabindex="4" size="40"&gt;&lt;/input&gt;&lt;br /&gt;
  &lt;input name="file5" type="file" tabindex="5" size="40"&gt;&lt;/input&gt;&lt;br /&gt;
  &lt;input name="submit" type="submit" value="Upload Files" tabindex="6" /&gt;
  &lt;/form&gt;
  &lt;p&gt;Note that upload speed depends on your internet connection speed.&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>All the forms are <code>encType="multipart/form-data"</code> to accomodate the file upload, and the ASP on the main page does a <code>Request.BinaryRead(Request.TotalBytes)</code> first thing with the form data. It then parses the data by delimiter, splitting it out into binary data (uploaded files) and text data (regular form fields). One of these regular form fields, <code>&lt;input name="task" type="hidden" value="T01" /&gt;</code>, is how it knows what to do with the submitted data (rename a file, upload a file, etc).</p>
  
  <p>So, why does uploading, and only uploading, not work in IE9?</p>
  
  <p>As above, the form submit method is the same for uploading and other (working) form actions, as is the server-side parsing of HTTP POST.</p>
  
  <p>Debugging has shown that the file upload popup never even submits data back to the parent page (or to itself), i.e.the form data is never <em>submitted</em> to the server in the first place. But, all the other forms work the same way and <em>do</em> submit.....</p>
  
  <p>Could this be something completely unrelated to code, like an IE9 security setting?</p>
  
  <p>Have even tried forcing IE8 compatability mode on IE9 (<code>&lt;meta http-equiv="X-UA-Compatible" content="IE=8" &gt;</code>), no change.</p>
  
  <p>Any assistance greatly appreciated.</p>
  
  <p>Thanks</p>
  
  <p>Lukas</p>
  
  <p><strong>Update:</strong></p>
  
  <p>1) "Doesn't work" means that the upload popup dissapears on submit (as it should), but nothing is ever submitted to the parent page. If I disable the auto-close on the popup: after clicking submit the text fields containing the path(s) to the file(s) to be uploaded are cleared, but nothing else happens. This suggests that it is submitting to the popup page rather than the parent page, but that doesn't really make sense, as the other (working under IE9) popup pages still correctly submit to the parent page. I'll try replacing the JS-generated popup page with a conventional ASP page that can show any HTTP POST data, and go from there.</p>
  
  <p>2) If I force compatability mode on the client side (IE9 compatability view button), it <em>does</em> work exactly as it should. This is more workaround than fix though. I suppose it does rule out browser settings though, as compatability mode would only affect page rendering?</p>