Reputation: 328
I have a page in which much of the HTML is generated by client side script (JQuery). I added a server side ASP.NET File control to upload files to server.
Now files are getting uploaded on the button click, which causes POSTBACK and so all the textboxes Company Name, Street Name, City Client etc are lost, as they were generated by JQuery.
I put the upload portion in UpdatePanel and registered AsyncPostBack Trigger, but then I am not getting HttpContext object at code-behind. I turned Async to a full postback using PostBackTrigger then the things became the same as before(i.e. without an update panel).
Now I have two questions from you people: - What is the use of an update panel if it behaves in the same way as the page without an update panel. (PostBackTrigger) - What should I do with the above problem?
CODE:
<asp:UpdatePanel ID="uploadUpdatePanel" runat="server">
<ContentTemplate>
<input id="fileField" type="file" runat="server" multiple="multiple" />
<asp:Button ID="uploadButton" runat="server" Text="Upload Documents" OnClick="uploadButton_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="uploadButton" />
<%--<asp:PostBackTrigger ControlID="uploadButton" />--%>
</Triggers>
</asp:UpdatePanel>
Upvotes: 0
Views: 1807
Reputation: 881
I would respectfully disagree with CrazyPaste's declaration that the UploadFile control doesn't work inside an update panel. I spent hours on this problem and finally found the answer on an obscure five-year-old post on the asp.net forums.
Check to see if your .aspx <form>
tag looks like this:
<form id="Form1" method="post" enctype="multipart/form-data" runat="server">
If it is an unadorned tag like <form id="Form1" runat="server">
that's probably your problem.
The majority of responses I found elsewhere mentioned setting the update triggers, as you have, and is correct, but setting the triggers is useless if your form tag is not correctly configured. Nowhere except on the 2007 forum page was this suggestion made. It works great now.
I hope this helps!
Upvotes: 0
Reputation: 3652
Basically, FileUpload controls don't work in UpdatePanels. I've run into this issue before and as far as I know, there's no way around it. You're just going to have to accept a full PostBack and work on saving user inputs.
Upvotes: 1