下面的代碼工作,讓我下載一個Word文檔,儘快下載文件.....不能在UpdatePanel中
Try
Response.BufferOutput = True
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Charset = ""
HttpContext.Current.Response.ContentType = "application/msword"
HttpContext.Current.Response.AddHeader("Content-Disposition", "inline;filename=myfile.doc")
HttpContext.Current.Response.Write(s)
'HttpContext.Current.Response.End()
HttpContext.Current.ApplicationInstance.CompleteRequest()
HttpContext.Current.Response.Flush()
Catch ex As Exception
Response.Write(ex.Message)
End Try
但我添加一個UpdatePanel - 它不下載該文件並沒有錯誤產生的?閱讀後,我添加了一個觸發器的ControlID值設置爲開始創建Word文檔文件的按鈕。我試過幾種代碼組合,但似乎沒有任何工作。有關如何縮小這個範圍的任何幫助?我也調試過,沒有錯誤顯示。我檢查了我的下載文件夾 - 什麼也沒有,嘗試設置沒有緩存(Response.Cache.SetCacheability(HttpCacheability.NoCache)),並沒有奏效。只要我刪除UpdatePanel,那麼所有似乎工作?
<asp:UpdateProgress ID="ProgressUpdate" AssociatedUpdatePanelID="UpdatePanel1" runat="server">
<ProgressTemplate>
<img alt="progress" src="../images/loading.gif" />
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="buttonDownloadFile" />
</Triggers>
<ContentTemplate>
..
完全失去了這一個。任何人都可以提出一個解決方法或如何解決這個問題?
這是可以下載使用XML HTTP文件在新的瀏覽器(請參閱[這裏](http://msdn.microsoft.com/en-us/library/ie/hh673569(v = vs.85).aspx)和[here](https://developer.mozilla.org/ en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Handling_binary_data)),但我想象UpdatePanel的代碼(服務器和/或客戶端)根本不支持它。 –
也許不是,但我會想有人可能有這個答案,因爲我的假設是別人會在我做之前嘗試過;-) – Computer
此解決方法是否有幫助? http://encosia.com/ajax-file-downloads-and-iframes/ –