One of the most well-known (as well as irritating) issues encountered with making use of Asynchronous Postbacks (such as those used with an ASP Update Panel), is that the ASP File Upload control will not work. Most people abstain from using an Update Panel whenever a FileUpload control is to be used. However in some implementations, this is not always a feasible solution.
The reason that a FileUpload will not work is because the FileUpload requires a Full Postback in order to work (as opposed to the Asynchronous Postback). Thus all we need to do is cause a Full Postback on our Submit button. A simple implementation is as follows:
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="upd1" runat="server">
<ContentTemplate>
<asp:Button ID="btn1" runat="server" />
<asp:FileUpload ID="fupl1" runat="server" />
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btn1" />
</Triggers>
</asp:UpdatePanel>
However, this will not work when your Update Panel is within a container control, such as a MasterPage. For example. Let's say that I have an Update Panel on my Master Page, and I wish to create a Postback Trigger for PageX.aspx which happens to have a FileUpload. In order to overcome this method, we may simply write a public method within the Master Page's backend:
public void RegisterPostbackTrigger(Control triggerOn)
{
ScriptManager1.RegisterPostBackControl(triggerOn);
}
Once we have done this, we need to create a reference to the Master Page, within the Pages that need to make use of this method. We do this by writing:
<%@ Reference VirtualPath="~/MasterPage.master" %>
on the front-end side of our Page, with VirtualPath being the Path of our Master Page. After we do this, we Build, and then go to our Page. Within the Page_Load, we simply need to write:
((ASP.masterpage_master)Page.Master).RegisterPostbackTrigger(btn1);
And there you have it. Now the Submit button will cause a full postback, allowing the File Upload to work as expected. The only caveat is that through Asynchronous Postbacks, the File within the File Upload is lost.