FileUpload control postback problem
11,147
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?
Author by
Manish
Updated on June 04, 2022Comments
-
Manish almost 2 years
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.