我想知道为什么我的方法FileUpload.HasFile总是为null ..

这是我使用的Xaml。

<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>


编辑:

我认为问题之一就是

    <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>


因为有页面的形式,还有我在这里使用的形式。如果不是IE,我有一个不显示的保管箱。所以当它是IE时,我只显示fileupload。
也许是因为有两种形式它不再触发了吗?

我应该明确使用此AjaxToolkit吗?

最佳答案

使用以下代码:

<%@ 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
        }
    }

关于c# - FileUpload.HasFile始终为null,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9666856/

10-13 08:03