I am encountering difficulties when attempting to use the ASP.NET File upload control.
What is happening is that when I call the file upload control from the code behind, I always get a FileUploadControl.HasFile = false.
I have carried out some research and tried different methods to no avail. The control is being used in the following scenario:
The control is contained in a div which is to be called as a popup dialog by means of JQuery. Together with the fileupload control there are two link buttons which will operate the mentioned control (Importing XML from file and manipulate).
Thanks.
Below is a sample of my code.
<asp:scriptmanager id="ScriptManager1" runat="server">
</asp:scriptmanager>
<div style="text-align: center; margin-left: auto; margin-right: auto">
<asp:fileupload id="FileUploadControl" runat="server" />
<asp:updatepanel runat="server">
<ContentTemplate>
<asp:LinkButton ID="Append" runat="server" Text="Append" OnClick="Append_Click"></asp:LinkButton>
<asp:LinkButton ID="Overwrite" runat="server" Text="Overwrite" OnClick="Overwrite_Click"></asp:LinkButton>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Append" />
<asp:PostBackTrigger ControlID="Overwrite" />
</Triggers>
</asp:updatepanel>
</div>
You need to remove the
UpdatePanel. You cannot upload a file on partial postback and if all you have in theUpdatePaneltriggers the file upload it’s not needed:NOTE: General tip for
UpdatePaneldevelopment. If you run into any weirdness that doesn’t make sense remove theUpdatePaneland test your code. UpdatePanel’s have lots of limitations depending on your page/controls complexity.