HtmlInputFile.value cleared after submit.

L

Lau Lei Cheong

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
 
G

Guest

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.aspx?scid=kb;en-us;32324
C#: http://support.microsoft.com/default.aspx?scid=kb;EN-US;32324

Bin Song, MC
 
L

Lau Lei Cheong

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top