gpt4 book ai didi

c# - doesn't have a file

转载 作者:行者123 更新时间:2023-11-30 22:57:10 27 4
gpt4 key购买 nike

这是我对网络表单的标记:

 <tr>
<td class="OnlyStandard">
<asp:Label ID="lCompanyLogoImageName" runat="server" AssociatedControlID="fupCompanyLogoImageName" CssClass ="smallfont">Company Logo:</asp:Label>
</td>
<td class="OnlyStandard">
<div>
<asp:FileUpload ID="fupCompanyLogoImageName" runat="server" CssClass ="smallfont"/>
<asp:Button ID="btnUploadLogo" runat="server" Text="Upload logo" OnClick="btnUploadLogo_Click"/>
<asp:HiddenField ID="hfTmpCompanyLogo" runat="server" />
</div>
</td>
<td></td>
</tr>

当我单击按钮 btnUploadLogo - 由于某些原因,指示文件已加载的字段为 false。不知道为什么

protected void btnUploadLogo_Click(object sender, EventArgs e)
{
if (fupCompanyLogoImageName.**HasFile** && fupCompanyLogoImageName.PostedFile != null)
{
string[] validExtentions = { ".jpg", ".png", ".bmp", ".gif" };
string extPostFile = Path.GetExtension(fupCompanyLogoImageName.PostedFile.FileName);
bool flValidExt = false;
foreach (string ex in validExtentions)
if (extPostFile.ToUpper().Equals(ex.ToUpper()))
{
flValidExt = true;
break;
}
if (!flValidExt)
{
string tmp = "";
foreach (string str in validExtentions) tmp += str + " ";
Response.Write("<script type='text/javascript'>alert('" + String.Format(this.GetLocalizationString("ErrorMsg_NotCorrectFileExtentsion.Text"), tmp) + "')</script>");
return;
}
hfTmpCompanyLogo.Value = String.Format("{0}_{1}", Guid.NewGuid(), fupCompanyLogoImageName.FileName);
}
}

fupCompanyLogoImageName.HasFile 为 false - 尚不清楚,因为已选择文件 enter image description here

文件名是St1.jpg - 可以在图片上看到

最佳答案

如果您的页面包含一个更新面板,那么您首先需要通过触发上传按钮 PostBackTrigger 用于获取这样的文件名

<asp:ScriptManager ID="ScriptManager1" runat="server"/> </asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="btnUploadLogo" />
</Triggers>
<ContentTemplate>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="btnUploadLogo" runat="server" Text="Upload" OnClick="UploadFile" />
</ContentTemplate>
</asp:UpdatePanel>

关于c# - <asp :FileUpload> doesn't have a file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53865859/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com