File Upload Control is not working in Update Panel
Posted by Ramani Sandeep on November 22, 2008
The essence of the problem is that the FileUpload control does not work with asynchronous postbacks, and therefore does not work from within an AJAX UpdatePanel.
The technique presented in this article allows the FileUpload control to work within an UpdatePanel, by forcing a full postback; however, the rest of the controls can still take advantage of the asynchronous postbacks provided by the UpdatePanel.
Solution
————
The trick is to force the file upload control to perform a full postback, and we do this using triggers. Triggers allow the developer to specify what will cause partial and full postbacks. They must be defined within the UpdatePanel but outside of the ContentTemplate. We want to create a trigger that will instruct the button that we are using for the upload to perform a full postback.
<asp:UpdatePanel ID=”UpdatePanel1″ runat=”server” UpdateMode=”conditional”>
<Triggers>
<asp:PostBackTrigger ControlID=”Button1″ />
</Triggers>
<ContentTemplate>
<asp:FileUpload ID=”FileUpload1″ runat=”server” />
<asp:Button ID=”Button1″ runat=”server” Text=”Upload” OnClick=”Button1_Click” />
</ContentTemplate>
</asp:UpdatePanel>
Adil said
This is very helpful but when update panel is on master page this is not identified button id. so then what to do.
Thanks
Ramani Sandeep said
you can dynamically fetch the content page buttonid on master page load event & asssign the post back trigger Control Id.
hope this idea will help you.
Shaker said
I have a big issue with in the Asp.Net Update Panel i.e Update panel contains two File upload controls one is for Image updalod and second one is for Document uplload and with in this i have one Ajax model popup event for entering Address details into Grid. The issue is after upload an image/Document if i click on Model PopUp link it’s showing JavaScript error “Microsoft JScript runtime error: ‘myScriptpagename’ is undefined”. Can any one please explan how to implement two FileUploads and Ajax model popups in a sing update panel or multiple?
Adil said
Pleasesent me soloution by e mail.
adilkhnajee@hotmail.com
shri said
he its working.Thanks
MyanmarASP.NET said
When I use Validation for other controls, fileupload has been disabled. how to solve?
Naresh said
I have same problem..When I use other controls with validation fileupload is disabled…………
swanand said
thx it working very good