Search code examples
c#javascriptjqueryasp.netupdatepanel

Update Panel AsyncPostBack and PostBack triggers


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>

Solution

  • 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.