Reputation: 341
I know there's many questions about the same topic, but I haven't see one that addresses my issue. So I have an UpdatePanel
in it's ContentTemplate
I have a ListView
with a Panel
, inside it is there's a FileUpload
, a Cancel button and an Upload button. When Upload button is pressed it calls a method, on the server side, that handles the file uploading business. My problem is that the HttpFileCollection
object is empty even though I did pick something.
This is an example of what I'm doing. Do to the company's policy I can't post the original programming, but this should be enough cause it's the only things running when uploading.
Client side:
<asp:UpdatePanel ID="upMain" runat="server">
<ContentTemplate>
<asp:ListView>
<asp:Panel ID="pnlFileUpload" runat="server" CssClass ="custom-menu">
<asp:FileUpload ID="fuUpload" runat="server" AllowMultiple="true" />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="OnUploadFile" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</asp:Panel>
<asp:ModalPopupExtender ID="mpeUpload" runat="server" TargetControlID ="imgBtnUploadFile" PopupControlID="pnlFileUpload" CancelControlID="btnCancel"
BackgroundCssClass="modalBackgroud">
<Animations>
<OnShown>
<%--The FadeIn and Display animation.--%>
<FadeIn Duration="0.25" MinimumOpacity="0" MaximumOpacity="1" />
</OnShown>
</Animations>
</asp:ModalPopupExtender>
</asp:ListView>
</ContentTemplate>
</asp:UpdatePanel>
Server side:
protected void OnUploadFile(object sender, EventArgs e)
{
HttpFileCollection files = Request.Files;
}
I have a break point on files
and when it hits, the keys
are 0, the content
is empty and so is the InputStream
. I've tried a few different things from setting the page's enctype ="multipart/form-data"
to many other things I can't remember, right now.
Still getting the hang of asp so any suggestions with explanation, would be greatly appreciated.
Upvotes: 2
Views: 2753
Reputation: 2108
From MSDN:
The following ASP.NET controls are not compatible with partial-page updates, and are therefore not designed to work inside an UpdatePanel control:
...
FileUpload and HtmlInputFile controls when they are used to upload files as part of an asynchronous postback.
...To use a FileUpload or HtmlInputFile control inside an UpdatePanel control, set the postback control that submits the file to be a PostBackTrigger control for the panel. The FileUpload and HtmlInputFile control can be used only in postback scenarios.
Upvotes: 2
Reputation: 11480
Your error is more than likely due to your UpdatePanel
. The premise of the Control is wonderful, sadly the execution is down right terrible. It often can create issues with your Page State. It does this in how the UpdatePanel
actually works.
The Control will take a copy of your page, store it in memory, and then it will reload your page in entirety. Which will impede your performance, but a side effect is when the page is reloaded, it will go through Asp.Net Page Life Cycle. Which can create a slew of issues if you aren't careful.
What I would do, would be move your FileUpload
and Upload Button
out of the panel, verify that it is uploading correctly. Once you confirm that, you know the UpdatePanel is the culprit. Then you can work within the constraints, or I would do manual Ajax Request.
Hopefully this explanation is in more detail for you.
Upvotes: 1