DottoreM
DottoreM

Reputation: 299

ASP.NET Issue with File Upload Control

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>                    
                    &nbsp;
                    <asp:LinkButton ID="Append" runat="server" Text="Append" OnClick="Append_Click"></asp:LinkButton>
                    &nbsp;
                    <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>

Upvotes: 1

Views: 2836

Answers (1)

rick schott
rick schott

Reputation: 20617

You need to remove the UpdatePanel. You cannot upload a file on partial postback and if all you have in the UpdatePanel triggers the file upload it's not needed:

<div style="text-align: center; margin-left: auto; margin-right: auto">
    <asp:fileupload id="FileUploadControl" runat="server" /> 
        &nbsp;
        <asp:LinkButton ID="Append" runat="server" Text="Append" OnClick="Append_Click"></asp:LinkButton>
        &nbsp;
        <asp:LinkButton ID="Overwrite" runat="server" Text="Overwrite" OnClick="Overwrite_Click"></asp:LinkButton>
</div>

NOTE: General tip for UpdatePanel development. If you run into any weirdness that doesn't make sense remove the UpdatePanel and test your code. UpdatePanel's have lots of limitations depending on your page/controls complexity.

Upvotes: 1

Related Questions