2

I'm having a FileUpload control on a aspx page inside a UpdatePanel with a button on click of which I want to set a label with the filename of the selected file.

Here is the code I have:

ASPX PAGE:

<div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:FileUpload runat="server" ID="fuSimple"></asp:FileUpload>
            <asp:Button runat="server" Text="Button" ID="btnPostback" 
                onclick="btnPostback_Click" />
            <br />
            <asp:Label ID="lblFileName" runat="server" Text="File Name: "></asp:Label>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

Code Behind:

protected void btnPostback_Click(object sender, EventArgs e)
    {
        lblFileName.Text = "File Name: " + fuSimple.FileName;  
    }

Every time I hit the button, I'm getting an empty string. What am I missing?

Also, when I do this without UpdatePanel it works fine.

Comments/help appreciated.

Manish
  • 6,106
  • 19
  • 64
  • 90
  • Duplicate of: http://stackoverflow.com/questions/35743/fileupload-control-inside-an-updatepanel-without-refreshing-the-whole-page – jrista Mar 02 '10 at 06:18

1 Answers1

6

The FileUpload control is not supported with ASP.NET AJAX and Asynchronous Postbacks. They require a full postback due to the nature of how a file upload works (multipart form data).

The following question should have useful answers: FileUpload control inside an UpdatePanel without refreshing the whole page?

Community
  • 1
  • 1
jrista
  • 32,447
  • 15
  • 90
  • 130