DotNet: HtmlInputFile.value cleared after submit.

  • lauleicheong / 204 / Thurs, 18 Jun 2009 11:35:00 GMT / Comments (3)
  • Hello everyone,

    I'm writing a web form to upload files. The page contains a number of
    tables to maintain the design(which VS.NET complain at the begin, but I
    resolved all of them later), a few HtmlInputFile object and a submit button.
    When I press the button, the code behind will save the file if the filename
    is not null.

    However when I press the button, nothing happened. I set a breakpoint in
    the first line of Submit_Click method and found its "value"="" and
    "Postedfile"=<undefined>. I've tried to add EnableViewstate=true but it
    still don't work.

    Can anyone suggest what else I have to check to fix this problem? Any
    help would be apperciated.

    Thanks in advance.

    Regards,
    Lau Lei Cheong

  • Keywords:

    htmlinputfile.value, cleared, submit, dotnet, .net

  • http://dotnet.itags.org/dotnet-tech/313839/«« Last Thread - Next Thread »»
    1. Hi,

      In order to upload file in ASP.NET and access it in server-side code, you need:
      1. Add the enctype="multipart/form-data" name-value attribute to the <form> tag as follows:
      <form id="Form1" method="post" enctype="multipart/form-data" runat="server">
      2. Add runat="server" attribute to the file control.
      <INPUT type=file id=File1 name=File1 runat="server" />
      See details of HOW TO: Upload a File to a Web Server in ASP.NET at:
      VB.NET: http://support.microsoft.com/default...b;en-us;323245
      C#: http://support.microsoft.com/default...b;EN-US;323246

      Bin Song, MCP

      binsong_mcp | Mon, 26 May 2008 17:06:00 GMT |

    2. I've checked the code and found none of them missing.

      Thanks anyway.

      "Bin Song, MCP" <anonymous...discussions.microsoft.com> bl
      news:0D19AB87-8EC0-4562-8732-D9C24C623768...microsoft.com g...
      > Hi,
      > In order to upload file in ASP.NET and access it in server-side code, you

      need:
      > 1. Add the enctype="multipart/form-data" name-value attribute to the

      <form> tag as follows:
      > <form id="Form1" method="post" enctype="multipart/form-data"

      runat="server">
      > 2. Add runat="server" attribute to the file control.
      > <INPUT type=file id=File1 name=File1 runat="server" />
      > See details of HOW TO: Upload a File to a Web Server in ASP.NET at:
      > VB.NET: http://support.microsoft.com/default...b;en-us;323245
      > C#: http://support.microsoft.com/default...b;EN-US;323246
      > Bin Song, MCP
      >


      lauleicheong | Mon, 26 May 2008 17:07:00 GMT |

    3. I've finally realized where the problem is. The problem, however, is not
      shown
      on the part I posted.

      The missing part is that: The mentioned code is on a large form that there
      is not only one button. Therefore except the one which forms' submit action
      is linked to others do not get the post data.

      Very sorry for my over-simplification of problem.

      "Bin Song, MCP" <anonymous...discussions.microsoft.com> bl
      news:0D19AB87-8EC0-4562-8732-D9C24C623768...microsoft.com g...
      > Hi,
      > In order to upload file in ASP.NET and access it in server-side code, you

      need:
      > 1. Add the enctype="multipart/form-data" name-value attribute to the

      <form> tag as follows:
      > <form id="Form1" method="post" enctype="multipart/form-data"

      runat="server">
      > 2. Add runat="server" attribute to the file control.
      > <INPUT type=file id=File1 name=File1 runat="server" />
      > See details of HOW TO: Upload a File to a Web Server in ASP.NET at:
      > VB.NET: http://support.microsoft.com/default...b;en-us;323245
      > C#: http://support.microsoft.com/default...b;EN-US;323246
      > Bin Song, MCP
      >


      lauleicheong | Mon, 26 May 2008 17:08:00 GMT |