I was setting up a ASP.NET Wizard control. The 3rd or 4th step had a file upload control on it, with a runat="server". The entire wizard control I wrapped in an ASP.NET UpdatePanel so that the wizard was all AJAXified. I had already fixed the "next" button for this wizard step so that it did a full postback to the server, not an asynchronous one - since I knew that was required to get a file upload to the server. However, the file was STILL not being posted back, atleast not on the first post. Subsequent posts would work fine. On a whim, I looked at the Firebug console to inspect the details of the request while it was in progress (Set a breakpoint in your code somewhere, then look at the Firebug console -- you'll see a "POST" entry with info about what was posted, headers for the request, etc). Below the POST entry, I saw a warning/error message I had never seen before:
This page has a file upload. However, the form tag does not have both the enctype=multipart/form-data and method=POST attributes. The file will not be uploaded.
Hmm... I thought about it a bit, and then looked at a normal page I had that had file upload controls on it. Sure enough, the form tag (there is always just one in ASP.NET) had the enctype attribute set automagically by ASP.NET if ASP.NET knew there was a file upload control on the page. Otherwise, it leaves it off. The Async update by the UpdatePanel was loading the FileUpload ok, but wasn't adding the enctype=multipart/form-data to the form tag attributes.
Solution: manually add the enctype to the page's form on Page_Load()
Page.Form.Attributes.Add("enctype", "multipart/form-data");
55 comments:
Thanks Adam! This was a great timesaver!
Lee
Thanks for posting this - I've been trying to figure this one out myself for the past week with no success.
Happy to help! :-)
I thank you from the bottom of my geeky heart for saving my entire week from despair trying to fix this damn bug!
Thanks for saving us time with your solution, i was missing the "enctype" attribute and getting this error, at last FileUpload working (from the first postback) on the update panels =D
thanks muchly
Hi Adam,
You are the man!!!
I think thanks is not just enough for you.
You cannot imagine what you have done. You saved us from a great problem. You are a genius absolutely.
Great Timesaver!
Keep it up!
hello adam ,
i just wanna to say that i try this code at the page load.
and now it's work prpperly.
thanks for ur great suggestion
manoj shukla
Thankyou very, very much! :)
Very thanks!
thanks dude it helped me a lot....
Thanks man, you save my life.
it's great for me.
Thanks,
This problem is looking small ,
but it was much time consumer.
Thanks for you solution.
Thanks Adam but I have another problem, that is when ever my web page post back the css will be disabled automatically only in IE 7.
Thanks In Advance
Does this help?
http://stackoverflow.com/questions/481308/asp-net-css-on-postback-in-ie-7-not-working
Still helping! Thanks!
A very big THANK YOU !! I've spent one day and a half trying the solution to this problem !!
excellent ...simply added code to pageLoad event and all fixed !!!
It also works when the FileUpload is in a UserControl, and this in turn is being used on the page. Tks!
Thanks it helped
greate thanks
THANKS LOTS HAVE NO WORDS TO THANK YOU
It is absolutly Rocking boss
Thanks a lot it has solved my problem.
thanks a lot, i spent a lot of time for this problem.
Stunning! That ends a four hour debugging battle from hell.... :-)
Thanks!
Wounderful..
Thanks your a life saver
Thank you Adam, this is great!!!
Simple..Great ..!!
Thanks a lot for this solution.It works for me..
Thanks alot its excelent code,
Thanks a lot. Just a line for solve a big problem.
thank you very much...its 100% solved my problems..
Thanks.It works fine for me.
Wow wow! That good one
wow your awesome... Spend hours trying to figure this one out. ++
tnx
Shoutout from Calgary, Canada. Thanks for sharing. Solved the issue for us.
Thanks.It works fine .
its great for me ........
thanks
This works absolutely fine. thanks!
I am not getting
Great.... It worked for me...
Thank you so much :)
nice and clean, you are great man! :)
Excellent Great
thanka a lot
thank you...was stuck for this from 1 hr
hello...can you give me demo source code for file upload because
Page.Form.Attributes.Add("enctype", "multipart/form-data");
line is not working in my application.
i will wait for your favorable replay,
Thank-you.
Thank you :)
thanku it works
Funciono, gracias
yesss
March 17, 2022
And still working this fix.
Thanks so much!
Post a Comment