c# - 在 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 方法现在也没有在这个页面上做任何事情。
解决方案
推荐阅读
- java - 如何从属性名称中给出的json中读取属性值
- caching - 如何在 .net-core-2.1 中使用内存缓存避免缓存未命中
- mysql - 使用 mySql 的简单 React 无法读取表记录
- c# - 在多个构造函数参数中注入具有相同接口的不同实现
- powershell - 在 PowerShell 中从 CNAME 解析主机名
- javascript - 阻止用户从嵌入的 YouTube 视频中获取 url/禁用剪贴板
- sql - Entity Framework 生成的 SQL 运行速度极慢
- web-scraping - 从延迟加载的视频中抓取视频链接
- reactjs - 注入一个反应组件作为背景图像
- javascript - 使用reactjs创建表时如何删除连续重复的数据条目