FileUpload.HasFile给始终为假 [英] FileUpload.HasFile give always false
本文介绍了FileUpload.HasFile给始终为假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的code在我的FileUpload控件是更新面板之外,但是当我点击保存按钮是更新面板下给fileUploadAttachment.HasFile = FALSE
this is my code where my FileUpload control is outside of update panel but when I click on save button which is under update panel give fileUploadAttachment.HasFile = false
ASPX
<asp:Literal runat="server" ID="lblAttachment" Text="Attachment:" /><asp:FileUpload
ID="fileUploadAttachment" runat="server" Width="488px" />
<asp:UpdatePanel ID="updatePanelAction" runat="server" UpdateMode="Always">
<ContentTemplate>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" ValidationGroup="Save" />
<asp:Button ID="btnTest" runat="server" Text="Test" Enabled="false" OnClick="btnTest_Click" />
<asp:Button ID="btnConfirmTest" runat="server" Text="Confirm Test" Enabled="false"
OnClick="btnConfirmTest_Click" />
<asp:Button ID="btnSend" runat="server" Text="Send" Enabled="false" OnClick="btnSend_Click" />
</ContentTemplate>
</asp:UpdatePanel>
CS
protected void btnSave_Click(object sender, EventArgs e)
{
CampaignBAL campaignBAL;
string tmpFileName = "";
User user;
Campaign campaignDetail = new Campaign();
int? campaignID;
if (fileUploadAttachment.HasFile) // return always false
{
tmpFileName = string.Format("{0}\\{1}{2}", Server.MapPath("TempUpload"), Guid.NewGuid(), Path.GetExtension(fileUploadAttachment.PostedFile.FileName));
fileUploadAttachment.PostedFile.SaveAs(tmpFileName);
}
}
请帮助我,我怎么能解决这个问题。
please help me how can I fix it
推荐答案
您需要添加回发触发器后内控制的UpdatePanel
:
You'll need to add postback triggers for controls that post within the UpdatePanel
:
<asp:UpdatePanel ...>
<Triggers>
<asp:PostBackTrigger ControlID="btnSend" />
</Triggers>
...
</asp:UpdatePanel>
这篇关于FileUpload.HasFile给始终为假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文