I was having problem while using File upload control which is inside the update panel and which was placed in user control. While doing post-back the value of PostedFile was blank, although page was properly valid.
Then I checked the Form property of Request object, the file upload control was missing in the AllKeys collection
We all know that if you want file uploads the form encode must be multipart/form-data. This is the reason why File Upload is not working properly inside Update Panel, lets understand this with following example.
Problem:
File upload is not working with update panel + asp.net
You are having two controls which needs to get display after one-another or post-back, first control does not have File upload and Second control does. Things to notice here is form tag will be reside either in ASPX page or Master page not in UserControl; and our File Upload is inside user control. Now when we load first control which does not have File Upload so the form will not encoded with multipart/form-data, now when you load second control which has the File Upload hence fort encode must be multipart/form-data, which is unfortunately not changing due to Update Panel.
Solution:
In problem definition we come to know that form must be encoded with multipart/form-data if we want to upload the file; solution is very simple, we just need to change encoded attribute of form with following single line!!!
Page.Form.Attributes.Add("enctype", "multipart/form-data");
49 comments:
excellent....worked well, thanks.
Thank you very much. It works flawlessly.
VicDo
Good work man...I am using Wizard control and my FileUpload control is in 3rd step and i was thinking that issue might have something to do with Wizard control and that was the case!....when it goes to next step, form encoding is not set...now i am setting in page load every time and it works great!!...thanks
Dude you rock!!!
Dude you rock!!!
Hi,
I am using fileupload control inside content page with update panel but it is not working yet with your solution.
Thank u so much..you saved my day :)
Thanks.. You saved my day dude. ;)
you solved my problem.. thx
Hi Imran,
Very nice post. It was very easy and use full. I am jalpesh and we met at Virutal tech days. Remember the entity framework guy.
hi
I am having still the same problem after
Page.Form.Attributes.Add("enctype", "multipart/form-data");
still i not able to upload the file in side the content page using FileUpload Control and if i use the same code out side the master page or in a fresh page the code works properly could you help me.
please reply soon
i am waiting... thank you
Hey Man..
Thanks a lot for sharing this great piece of blog.you are a life saver man... thanks a ton....
Karunaker , Angad
hey thanks for u r great knowledge
thanks, working great!!!
If you have an updatepanel you can also put a trigger on it to to a POST
......
this worked for me
Regarding using an upload control in a wizard.... This helped but the trick was I had accidently created the step for the upload control as a WizardStepTemplate instead of a WizardStep. Once I put the File Upload Control inside of Wizard Step 3, Then on Next (Goes to Step 4) I perform the upload and display the final it worked great!
YUO ARE GOD!
Thanks so much for this...
Great and simple, good job man.
Thanks so much.
I think this solution might be perfect.
I tried this but it is not working.
Actually in which area we need to write the Page.Form.Attributes.Add("enctype", "multipart/form-data");
.
please explain.
Marvelous solution...
very good ,,,,i works correctly
Wow., Thank you so much . I am dying to find a solution since so many days.
You helped me a lot. It worked excellent .
Thanks a lot. You saved my time and my life.
excellent....
worked well
Thank You Very Much.
thanks for sharing useful work it helps me a lot
awosome solution
excellent!
It solved my problem
Thanks for your help works fine
Thanks
But we need to for to implement this with this .
Step:1
Add Page.Form.Attributes.Add("enctype", "multipart/form-data")
in PageLoad
Step: 2 Add Your content as
Your Content....( )
Thanks A LOT man ! I was going crazy with my uploads working only on second clic, and all the answers on the web leading to other stuff... Finally ended up on a stack overflow question pointing this page. Now it's solved !
its working. thanks
oh great..thaaks ...
Awwwsssuuuummmmmmmmm work..dude......
it's working........
thanxxxxxxxxxxx
I followed the way as u post... but unable to resolve the problem... Please somebody help me with this...
I have tried this, "enctype="multipart/form-data" is already in my form TAG but still does not work, any idea why?
Thanks
I did try as per your POST it did't work, may be I am doing something wrong, but I found one link which explain the reason of why update panel and file upload does not work together.
It worked well.
Please see below link:
http://www.aspsnippets.com/Articles/Using-FileUpload-Control-inside-ASP.Net-AJAX-UpdatePanel-Control.aspx
Thanks. BIg help
Thank you very much..
Really it saved for me lot of time.
It was not worked for me. I found another solution for this. I want to share with you
Please check this link :-
http://coding-spirit.blogspot.in/2012/11/fileupload-control-is-not-working.html
Thank you Imran Bhai.. u rock!!!
It didn't worked for me. :(
It didnt helped me.
i have written that code in page load event of master page and content page as well but it didnt worked.
Great. It worked. Thanks a lot
Thank you very much.
It helped me a lot
Thanks a lot :-)
How about if you want to Download ? I tried to do the same and it dint work
You saved my life!!! Thanks a lot!!!!!!!!
Thanks a lot.....
Superb Dear...
Post a Comment