c# - FileUpload.HasFile 始终为 false

标签 c# asp.net

这是我的代码,其中我的 FileUpload 控件位于更新面板之外,但是当我单击更新面板下的保存按钮时,给出 fileUploadAttachment.HasFile = false

ASPX

<asp:Literal runat="server" ID="lblAttachment" Text="Attachment:" /><asp:FileUpload
            ID="fileUploadAttachment" runat="server" Width="488px" />
        <asp:UpdatePanel ID="updatePanelAction" runat="server" UpdateMode="Always">
            <ContentTemplate>
                <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" ValidationGroup="Save" />
                <asp:Button ID="btnTest" runat="server" Text="Test" Enabled="false" OnClick="btnTest_Click" />
                <asp:Button ID="btnConfirmTest" runat="server" Text="Confirm Test" Enabled="false"
                    OnClick="btnConfirmTest_Click" />
                <asp:Button ID="btnSend" runat="server" Text="Send" Enabled="false" OnClick="btnSend_Click" />
            </ContentTemplate>

        </asp:UpdatePanel>

CS

protected void btnSave_Click(object sender, EventArgs e)
{
    CampaignBAL campaignBAL;
    string tmpFileName = "";
    User user;
    Campaign campaignDetail = new Campaign();
    int? campaignID;

    if (fileUploadAttachment.HasFile) // return always false
    {
        tmpFileName = string.Format("{0}\\{1}{2}", Server.MapPath("TempUpload"), Guid.NewGuid(), Path.GetExtension(fileUploadAttachment.PostedFile.FileName));
        fileUploadAttachment.PostedFile.SaveAs(tmpFileName);
    }
}

请帮我解决一下

最佳答案

您需要为在 UpdatePanel 中发布的控件添加回发触发器:

<asp:UpdatePanel ...>
  <Triggers>
    <asp:PostBackTrigger ControlID="btnSend" />
  </Triggers>
  ...
</asp:UpdatePanel>

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

相关文章:

c# - task.factory startnew 的使用使我的网站时不时地取消用户登录

javascript - ASP.NET 计时器 + 更新面板 : How do I stop the event from continually registering?

c# - 请求中对象的值在wcf服务中始终为null

c# - 自引用多对多递归关系代码优先 Entity Framework

c# - C# 中的可区分联合

c# - 手动实现UpdatePanel

c# - WCF WSHttpBinding SOAP 安全协商失败

c# - 如何访问 ApiController 中的 Response

c# - 查询应该放在 ASP.NET MVC 中的什么地方

c# - 如何自动打印带有详细选项的pdf?