Tuesday, April 24, 2012

ASP.NET - A FileUpload inside an UpdatePanel problem solved

The explaining of this problem is quite simple, though it took me plenty of time to solve. The FileUpload control requires a full PostBack for the file loading. (I hope everyone knows that UpdatePanel is a partial Postback)
Two things have to be done to cause a full PostBack:
A. Register the control that triggers the form submitting as a full PostBack trigger of the update panel.
B. Assign the enctype specification of the form containing the UpdatePanel.



<form id="form1" runat="server" enctype="multipart/form-data">
<asp:UpdatePanel runat="server" ID="my_update_panel" UpdateMode="Conditional">
<Triggers>
<asp:PostBackTrigger ControlID="btn_submit_form" />
</Triggers>
       <ContentTemplate>
              <asp:FileUpload ID="file_upload_01" runat="server" />
              <asp:Button ID="btn_submit_form" runat="server" onclick="do_on_submit_form" />
        </ContentTemplate>
    </asp:UpdatePanel>
</form>

Enjoy!

No comments:

Post a Comment