Attempting to use a FileUpload or AsyncFileUpload control in an updatepanel on a NET 4.5/C# web application.
I've tried using either standard Scriptmanager or ToolKitScriptManager in my masterpage.
My Save button is set as a PostBackTrigger (tried AsyncPostbackTrigger too).
No matter what, my (Async)FileUpload.HasFile always returns false.
Remove the updatepanel and both uploadcontrols work fine.
What really throws me is that I have this working in another project (scriptmanager in masterpage, Fileupload in updatepanel, SaveButton is PostbackTrigger).
Is there some specific AJAX version or .NET version that can cause problems?
This is extremely frustrating.
In Page_Load add:
Page.Form.Attributes.Add("enctype", "multipart/form-data");
FileUpload
FileUpload requires full page request. This is a limitation of the XmlHttpRequest component used in all AJAX frameworks for asynchronous calls to the application.
I think you are using Full PostBack, although FileUpload is inside **UpdatePanel.
For example,
AsyncFileUpload
If you use AsyncFileUpload with UpdatePanel, AsyncFileUpload.HasFile should only checked inside UploadedComplete (you cannot check inside Button click event).
The reason is AsyncFileUpload is uploaded the file via Async by itself.
Note: make sure you use ToolkitScriptManager instead of ScriptManager
Other Thoughts
I personally do not like using AsyncFileUpload inside UpdatePanel. Instead, I'll rather use Full PostBack if I need to upload a file.
Adding the button to the UpdatePanel's trigger tag, I got it working:
I did not have to do anything different server-side (like user5159158's answer).
File Upload will not work with a partial post back. It requires full page request. So add the below line in your page load.