FileUpload1.HasFile总是返回false [英] FileUpload1.HasFile is always returning false
问题描述
我使用ASP.net文件上传控件上传文件。
我FileUpload1.HasFile总是返回false。
I am uploading file using ASP.net File upload control. My FileUpload1.HasFile is always returning false.
if (FileUpload1.HasFile)
{
DBOperations db = new DBOperations();
try
{
FileUpload1.SaveAs(Server.MapPath("~/uploadedImages/" + db.uploadImage(System.IO.Path.GetExtension(FileUpload1.FileName)) + System.IO.Path.GetExtension(FileUpload1.FileName)));
}
catch (Exception Ex)
{
String he = Ex.Message;
}
}
我使用以下ASP.net code
I am using following ASP.net Code
<asp:UpdatePanel ID="fileUpload" runat="server">
<ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnUploadFile" EventName="Click" />
</Triggers>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUploadFile" Text="Upload File" runat="server"
onclick="btnUploadFile_Click" />
<br />
<asp:RegularExpressionValidator ID="revImage" ControlToValidate="FileUpload1" ValidationExpression="^.*\.((j|J)(p|P)(e|E)?(g|G)|(g|G)(i|I)(f|F)|(p|P)(n|N)(g|G))$" Text="Invalid image type" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
我甚至通过移除AsyncPostBackTrigger,甚至删除整个ASP尝试:的UpdatePanel然后还要我FileUpload1.HasFile始终返回false
I have tried even by removing AsyncPostBackTrigger and even by removing Whole asp:updatePanel then also my FileUpload1.HasFile always returns false.
推荐答案
ASP.NET的AJAX的事不支持的UpdatePanel文件上传开箱。该触发器变成一个 PostBackTrigger
(这会导致一个完整的页面加载),或者使用别的上传的文件。
ASP.NET's "AJAX" thing doesn't support file uploads in UpdatePanels out of the box. Change that trigger into a PostBackTrigger
(which causes a full page load) or use something else to upload the file.
这篇关于FileUpload1.HasFile总是返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!