0
爲簡單起見,我有一個簡單的2面板多視圖。首先有一個FileUpload控件,第二個是一個按鈕,用於發送包含該文件的電子郵件作爲附件。當我在第二個選項卡上選中「FileUpload1.HasFile」時,它將返回爲false。如果我回到視圖1,其他控件的所有狀態都已正確維護,除非文件上載空白。ASP.net 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));
}
任何想法???