Home » Category » DotNet

DotNet: HtmlInputFile.value cleared after submit.

204| Mon, 26 May 2008 17:05:00 GMT| lauleicheong| 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 & Tags: htmlinputfile.value, cleared, submit, dotnet, .net

URL: http://dotnet.itags.org/dotnet-tech/313839/
 
«« Prev - Next »» 3 helpful answers below.
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 |

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 |

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 |

DotNet Hot Answers

DotNet New questions

DotNet Related Categories