c# - FileUpload.HasFile 错误地返回 false
问题描述
ASP 控件FileUpload
总是false
为方法返回FileUpload.HasFile
。我曾尝试使用触发器,但这对我不起作用。
这是按钮方法
protected void btnUploadFile_Clicked(object sender, EventArgs e)
{
testMethod();
}
这是testMethod()
if 语句总是评估为假。
protected void testMethod()
{
if(FileUploadImage.HasFile)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "NoDatabaseAlertMessage", "alert('it work')", true);
}
else
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "NoDatabaseAlertMessage", "alert('no work')", true);
}
}
Edit1:这是我尝试实现的 html 触发器内容,但未成功
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Always" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="btnUploadFile" />
</Triggers>
</asp:UpdatePanel>
<asp:FileUpload ID="FileUploadImage" runat="server" />
<asp:Button ID="btnUploadFile" runat="server" Text="Upload File" class="btn btn-primary transition-3d-hover" OnClick="btnUploadFile_Clicked" />
</div>
解决方案
我注意到我团队中的某个人对 .aspx 文件中的代码进行了错误的编辑,并且没有关闭表单标记。在我关闭表单标签后,问题消失了,控件按预期运行。
推荐阅读
- typescript - Mongoose (Typegoose) 和 RXJS
- git - 未更改的文件上的 Git 合并冲突
- ruby - 获取原始 rake 任务的名称或传递参数
- fonts - Webfont 生成器 - 希腊字母“μ”的问题
- java - 使用Kafka消费者池是否正确?
- python - Scikit-learn:在超参数调整后对整个数据集使用交叉验证
- php - 按 ID 过滤 XML 文件
- ios - JSON 有问题 - 数据重复
- objective-c - 在 Objective-C 生成的代码中 Protobuf 缺少“列表”后缀
- twilio - Twilio 合并子录音