[英]download file inside updatepanel with out PostBackTrigger
I am using this part of code to download file using the onClick event for imageButton inside UpdatePanel , it works fine if I add the imageButton as PostBackTrigger for the updatePanel, is there away to do that with out full postback? 我正在使用这部分代码来通过UpdatePanel内的imageButton的onClick事件下载文件,如果我将imageButton添加为updatePanel的PostBackTrigger ,则可以正常工作, 有没有完整的回发功能吗?
Dim stream As IO.Stream = Nothing
Dim bytesToRead As Integer = 10000
Dim buffer As Byte() = New Byte(bytesToRead - 1) {}
Try
Dim fileReq As Net.HttpWebRequest = CType(Net.HttpWebRequest.Create(FileURL), Net.HttpWebRequest)
Dim fileResp As Net.HttpWebResponse = CType(fileReq.GetResponse(), Net.HttpWebResponse)
If fileReq.ContentLength > 0 Then fileResp.ContentLength = fileReq.ContentLength
stream = fileResp.GetResponseStream()
Dim resp = HttpContext.Current.Response
resp.ContentType = "application/octet-stream"
resp.AddHeader("Content-Disposition", "attachment; filename=""" & FileName & """")
resp.AddHeader("Content-Length", fileResp.ContentLength.ToString())
Dim length As Integer
Do
If resp.IsClientConnected Then
length = stream.Read(buffer, 0, bytesToRead)
resp.OutputStream.Write(buffer, 0, length)
resp.Flush()
buffer = New Byte(bytesToRead - 1) {}
Else
length = -1
End If
Loop While length > 0
Finally
If stream IsNot Nothing Then
stream.Close()
End If
End Try
I found the solution. 我找到了解决方案。 @HATCHA's answer on Asp:progress won't end anitmation when file is downloaded from ashx file was great.
从ashx文件下载文件时, @ HATCHA对Asp:progress的回答不会结束动画 。 what @VDWWD said was wonderful , But not in my case, because I need a button to create the pdf file before starting the download .
@VDWWD所说的话很棒,但就我而言不是,因为在开始下载之前 ,我需要一个按钮来创建pdf文件。 which means the client side click won't be useful.
这意味着客户端点击将无用。
ScriptManager.RegisterClientScriptBlock(Me, GetType(Page), "downloadFileExport", "javascript:window.location ='" & ResolveUrl("~/report/download.ashx?url=" & url & "&fName=" & fName) & "';", True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.