Note that there are some explanatory texts on larger screens.

plurals
  1. POFile upload is reset on submit button click
    text
    copied!<p>I am using upload feature in my asp website. So i am using file input type. But this control add a default upload button browse and a textbox where path is shown after selecting file in Internet explorer. I don't want to show browse button etc. So what i did is add a button "Attach a File" and i have written script 'triggerFileUpload' function where i make it to click on upload control. So now when i click on "Attach a File" button browse for file windows appears and can select file to upload. But when i click on submit button the file upload control becomes reset and file is not uploaded. Error is that on clicking to submit button the file control becomes null. It happens only in internet explorer. So please help me to solve this.Below is code which can show the problem i am facing in IE.Same problem comes if i use asp:FileUpload control also. (my plan is to hide the file control and show only attach file button to user).</p> <pre><code>&lt;%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;/title&gt; &lt;script type="text/javascript"&gt; function triggerFileUpload() { document.getElementById("FileUploaddd2").click(); } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div&gt; &lt;input id="Button2" type="button" onclick="triggerFileUpload()" value="Attach a File" /&gt; &lt;input type="file" id="FileUploaddd2" runat="Server" /&gt; &lt;br /&gt; &lt;asp:Button ID="btnSubmit" runat="server" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" Text="Submit" /&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Download the sample code <a href="http://incometaxsoft.com/WebSite9.zip" rel="noreferrer">here</a></p> <p><strong>UPDATE</strong></p> <p>To reproduce the error i am facing</p> <p>1) run the project i have given in the download link</p> <p>2) Test in Internet explorer-any version</p> <p>3)Click on attach a file button (not on browse,it is intended to make visible false,here shown only for example purpose)</p> <p>4)browse for files in windows appearing and click OK</p> <p>5)now click on Save button.</p> <p>When save button is clicked btnsave_Click function should trigger,but it is not triggering.If i click again on save button btnsave_Click gets triggered.But this time the upload control will not be having the file selected.you can see it in the textbox provided by browse control also(only for showing this i made browse control as visible)</p> <p>So now question why btnsave_Click is not triggered for the first time?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload