【发布时间】:2014-03-28 16:24:01
【问题描述】:
我的文件上传控件不是 UpdatePanel 的一部分。它只是驻留在asp:panel 中。当我单步调试调试器时,我看到正确填充了 FileName 属性、FileBytes、PostedFile 等,但 HasFile 本身是错误的。由于 FileName 属性具有预期值,但 HasFile 为假,因此我束手无策。这个solution 也没有帮助!
<asp:Panel id="AddEditReport" runat="server" Visible="false" style= "display:inline;" >
<asp:HiddenField ID="ReportField" runat="server" Value="Report" />
<table width="100%">
<tr>
<td>Title:</td>
<td><asp:TextBox ID="TextBox_Report" runat="server" Width="342px"></asp:TextBox></td>
</tr>
<tr>
<td valign="top"><asp:Label ID="Description_Label" runat="server" Text="Header Description" /></td>
<td><asp:TextBox TextMode="MultiLine" ID="Description" runat="server" Width="342px" height="250px" AutoPostBack="false"/></td>
</tr>
<tr>
<td>
<asp:Label ID="DisplayOrder_Label" runat="server" Text="Display Order" />
</td>
<td>
<asp:TextBox ID="TextBox_DisplayOrder" runat="server" Width="42px" MaxLength="2" AutoPostBack="false"/>
</td>
</tr>
<tr>
<td><asp:Label runat="server" ID="FileUploader_Label" Text="Copy of file: "/></td>
<td><asp:FileUpload ID="FileUpload_Report" runat="server"/></td>
</tr>
</table></asp:Panel>
<asp:Panel ID="Button" runat="server">
<asp:Button id="Save" runat="server" Text="Save" OnClick="SaveButton_clicked"/>
<asp:button id="Back" runat="server" Text="Back" OnClick="BackButton_clicked" UseSubmitBehavior="False"></asp:button><%
int id;
if (!string.IsNullOrEmpty(Request.QueryString[QuerystringID]))
{
id = int.Parse(Request.QueryString[QuerystringID]);
if (string.IsNullOrEmpty(ReportRepository.GetReportById(id).FilePath))
{
%> <a onclick="return confirm('Are you sure you wish to delete this heading?')" href="FileUpload.aspx?id=<%=id.ToString()%>&delete=true" target="_self">
<input type="button" value="Delete Heading"/>
</a>
<%
}
}
%></asp:Panel>
这是我的整个页面。
HasFile 失败的 sn-p 背后的代码:
if (FileUpload_Report.HasFile)/*Fails always*/
{
FileInfo fileInfo = new FileInfo(FileUpload_Report.FileName);
// First add the report to get the ID.
ReportRepository.Add(report);
// Then update with the created filepath.
report.FilePath = PathRoot + @"/" + GetFilename(report) + fileInfo.Extension;
// Update the old report with a deleteddate.
ReportRepository.Update(oldReport);
ReportRepository.Update(report);
FileUpload_Report.SaveAs(Server.MapPath(PathRoot) + "\\" + GetFilename(report) + fileInfo.Extension);
}
请帮忙。
【问题讨论】:
-
为什么不把 FileUpload 放到更新面板中?
标签: c# asp.net file-upload