Monday, November 7, 2011

File Upload Control inside update panel - ASP/AJAX

Today when I was developing my asp.net application at my office, I came across with some difficulties when dealing with the File Upload Control that I had in asp.net. I have placed a button and a file upload control with some other controls inside an update panel. The issue was whenever I clicked on the upload button, the property "HasFile" of the file upload control gave me "false". hmm, what went wrong?? was it because of the file upload does not post back data when it reside inside a update panel...???  

This issue made me read some articles and do some research on this and it was due to missing some attributes on POST method. huh???

So what can we do to avoid this.

Add the following code in your page_Load() method:


VB
Page.Form.Attributes.Add("enctype", "multipart/form-data")

C#

Page.Form.Attributes.Add("enctype", "multipart/form-data");



That's all and my file upload control started working fine !!!

Happy Coding.

No comments:

Post a Comment