2011-03-09 46 views
0

如何在response.redirect之後優化代碼? 我想強制文件下載使用response.redirect,一旦文件被下載,我想顯示模式彈出發送電子郵件。在asp.net中下載文件併發送電子郵件

但在response.redirect之後,彈出窗口沒有被調用。 請幫助我如何做到這一點,

感謝



UPDATE:
感謝您的答覆。 我正在這樣做。有什麼建議麼?

Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName.Name); 
       long FileSize = myFile.Length; 
       byte[] Buffer = new byte[(int)FileSize]; 
       myFile.Read(Buffer, 0, (int)FileSize); 
       myFile.Close(); 

       Response.BinaryWrite(Buffer); 
       // Response.Redirect(filepath,false); 
       Response.Flush(); 
       Response.Close(); 
       ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowPopup", "window.setTimeout('PopupModal()',50);", true); 

回答

0

你不能,除非你要執行的代碼被稱爲在進入使用Response.Redirect時指定的位置。一旦你轉移控制權,就是這樣,你結束了響應 - 執行環境不再存在,無論你轉移到哪裏接管。

如果你想推送一個文件,看看Response.WriteFile而不是這樣,你可以讓他們下載文件並繼續執行你的代碼,全部在一個頁面內,或者至少在頁面之間傳輸控制其中載有具體行動;這裏是MSDN link欲瞭解更多信息。