Reputation: 4182
I am wondering why my method FileUpload.HasFile is always null ..
This is the Xaml I use .
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanelAddFiles" runat="server" UpdateMode=Conditional>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="LkUpload" />
</Triggers>
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Panel ID="PanelAddFiles" runat="server">
<div class="PanelAddFiles">
<asp:LinkButton ID="LkUpload" runat="server" OnClick="LkUpload_Click" Visible="false">Upload</asp:LinkButton>
<asp:FileUpload ID="FileUpload1" runat="server" Visible="false" />
</div>
</asp:Panel>
Edit :
I think one of the problem would be this
<form action="Upload/Default.aspx" enctype="multipart/form-data" method="post" id="frm">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanelAddFiles" runat="server" UpdateMode=Conditional>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="LkUpload" />
</Triggers>
<ContentTemplate>
</ContentTemplate>
</asp:UpdatePanel>
<asp:Panel ID="PanelAddFiles" runat="server">
<div class="PanelAddFiles">
<asp:LinkButton ID="LkUpload" runat="server" OnClick="LkUpload_Click" Visible="false">Upload</asp:LinkButton>
<!--<asp:FileUpload ID="FileUpload1" runat="server" Visible="false" />-->
<ajaxToolkit:AsyncFileUpload runat="server" ID="FileUpload1" />
<asp:Panel ID="Dropbox" runat="server">
<div class="dropbox">
<div class="dragzone">
</div>
<span class="message">
drop files here to upload
</asp:Panel>
</div>
</asp:Panel>
</form>
</div>
because there is the form of the page, and also the form I use here . I have a dropbox that I show or not if it's IE or not . So when it's IE i just display the fileupload . Maybe it's because there are two forms that it's not firing anymore ?
Should i Definitly use this AjaxToolkit ?
Upvotes: 1
Views: 6481
Reputation: 12721
FileUpload doesn't work inside an UpdatePanel. You must use AsyncFileUpload from ASPNET AJAX control Toolkit.
When you use AsyncFileUpload you must set the right params in the form tag, that is placed in your Page or MasterPage:
<form id="form1" runat="server" enctype="multipart/form-data" method="post">
If you don't set the right enctype and method UploadedComplete will never fire, and you won't be able to get FileUpload.FileBytes since FileUpload.HasFile returns true only during UploadedComplete execution.
Besides, prevoius versions of AsyncFileUpload didn't work on Chrome. Actual version solved the problem.
Upvotes: 6