为了简单起见,我有一个简单的 2 面板多视图。第一个是 FileUpload 控件,第二个是一个按钮,用于发送带有文件作为附件的电子邮件。当我在第二个选项卡上检查“FileUpload1.HasFile”时,它返回为假。如果我回到视图 1,所有其他控件的所有状态都得到了适当的维护,除了 fileupload 是空白的。
<asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
<asp:View ID="Step1" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" Width="450" EnableViewState="true" />
</asp:View>
<asp:View ID="Step2" runat="server">
<asp:Button ID="btnSubmitForm" runat="server" Text="Submit Data" onclick="btnSubmitForm_Click" />
</asp:View>
</asp:MultiView>
当用户导航到视图 2 并单击按钮时:
//Initialize smtp server
SmtpClient smtp = new SmtpClient("myHost");
//Initialize mail message object
MailMessage mail = new MailMessage();
//Set all mail message params (to, cc, subject etc...)
//attach file, this is where it fails to recognize the attached document. bool is false :(
if (FileUpload1.HasFile)
{
mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
}
有任何想法吗???