FileUpload.HasFile() always null

本文关键字:always null HasFile FileUpload | 更新日期: 2023-09-27 18:27:34

这是我在UpdatePanel中使用的代码。

FileUploadAsync.HasFile()始终为null。

我想知道我的asp.net页面出了什么问题。。。

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="Server" />
<asp:UpdatePanel ID="UpdatePanelAddFiles" runat="server" UpdateMode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="LkUpload" />
    </Triggers>
    <ContentTemplate>
    <asp:LinkButton ID="LkUpload" runat="server" OnClick="LkUpload_Click" Visible="false">Upload</asp:LinkButton>
        <ajaxToolkit:AsyncFileUpload runat="server" ID="FileUploadAsync" />
    </ContentTemplate>
</asp:UpdatePanel>

FileUpload.HasFile() always null

您是否尝试过将文件上传到更新面板之外?我以前也遇到过这个问题。

我有这个工作,尝试一下,让我知道。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="futest.aspx.cs" Inherits="erpweb.futest" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="smTest" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="upTest" runat="server">
        <ContentTemplate>
            <ajaxToolkit:AsyncFileUpload ID="AsyncFileUpload1" runat="server" 
                onuploadedcomplete="AsyncFileUpload1_UploadedComplete" />
        </ContentTemplate>
    </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>

码尾:

    protected void AsyncFileUpload1_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
    {
        if (AsyncFileUpload1.HasFile)
        {
            //do save process here
        }
    }