Results 1 to 4 of 4

Thread: File upload is reset on submit button click

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    285

    File upload is reset on submit button click

    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).
    Code:
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
          function triggerFileUpload() {
              document.getElementById("FileUploaddd2").click();
          }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <input id="Button2" type="button" onclick="triggerFileUpload()" value="Attach a File" />
         <input type="file" id="FileUploaddd2" runat="Server" />
         <br />
        <asp:Button ID="btnSubmit" runat="server" BorderColor="Black"
                                BorderStyle="Solid" BorderWidth="1px"
                                Text="Submit" />
        </div>
        </form>
    </body>
    </html>

  2. #2
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: File upload is reset on submit button click

    You're reinventing the wheel, IMHO. I do not think the normal file input's Click event can work like that. I'd rather add an event listener and call it from there.

    See here :

    http://www.w3schools.com/jsref/dom_obj_fileupload.asp

    and here :

    http://www.w3schools.com/jsref/dom_obj_event.asp
    VB.NET MVP 2008 - Present

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2013
    Posts
    285

    Re: File upload is reset on submit button click

    can you please give an example?

  4. #4
    Lively Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    122

    Re: File upload is reset on submit button click

    I know I am a little late to this party....but I agree with HanneSThEGreaT on this one. My advice would be to look at something yui uploader or any of the dozen free upload controls out there.

    http://yuilibrary.com/yui/docs/uploader/

    Most all of them have plenty of examples.

    -zd

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width