views:

269

answers:

1

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.

+4  A: 

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: http://stackoverflow.com/questions/35743/fileupload-control-inside-an-updatepanel-without-refreshing-the-whole-page

jrista
Thanks.......... :)
Manish