首页 > 解决方案 > 在 asp.net Web 表单面板属性中使用 FileUpload?

问题描述

当我尝试在 asp:Panel 属性中上传文件时,我的 fileuploader.HasFile 始终为 false。

<asp:Panel ID="pnlDetay" runat="server" Visible="false">
            <table>
                
                <tr>
                    <td style="width: 175px; text-align: right; vertical-align: central">
                        <asp:Label ID="Label12" runat="server">Belge</asp:Label>
                    </td>
                    <td style="width: 200px; text-align: left">
                        <asp:DropDownList ID="ddl_BELGELER_BelgeTanimID" runat="server" Width="200px"></asp:DropDownList>
                    </td>

                    <td style="width: 175px; text-align: right">
                        <asp:Label ID="lbl_BelgeYol" runat="server"></asp:Label>
                    </td>
                    <td id="td_BelgeIndir" runat="server" style="width: 175px; text-align: left">
                        <asp:TextBox ID="txt_BELGELER_BelgeYol" runat="server" Style='text-align: left' Width="175" Enabled="false"></asp:TextBox>
                        <a runat="server" id="lnk_Indir" style="float: none;"
                            target="_blank" href="../../Images/filedownload.png">
                            <img style="border-style: none; border-width: 0;" src="../../Images/filedownload.png" /><b>Belgeyi İndir</b></a>
                    </td>
                    <td id="td_BelgeYukle" runat="server" style="width: 175px; text-align: right">
                        <asp:FileUpload id="FileUploadControl" runat="server" Width="125px" /> // THIS IS MY FILEUPLOAD
                        <asp:Button runat="server" id="UploadButton" height="25px" text="Yükle" onclick="UploadButton_Click" />
                    </td>
                </tr>
            </table>
        </asp:Panel>

此代码在面板内

这是后面的代码:

protected void UploadButton_Click(object sender, EventArgs e)
{
    if (FileUploadControl.HasFile) // Always false
    {
        try
        {
            string filename = Path.GetFileName(FileUploadControl.FileName);
            FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
            //StatusLabel.Text = "Upload status: File uploaded!";
        }
        catch (Exception ex)
        {
            //StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
        }
    }
}

我看到了有关 UpdatePanel 的示例,但没有看到 Panel 的示例。我不能在这里使用触发器。

编辑:我添加了我的 asp:Panel 代码的完整标记。我的 Page_Load 方法现在也没有在这个页面上做任何事情。

标签: c#asp.netfile-uploadwebformsautopostback

解决方案


推荐阅读