简体   繁体   English

在不带PostBackTrigger的updatepanel中下载文件

[英]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.

相关问题 即使文件下载完成,带有PostbackTrigger的UpdatePanel也冻结 - UpdatePanel with PostbackTrigger froze even after file download is complete UpdatePanel里面的ASP.NET Repeater,需要创建PostBackTrigger - ASP.NET Repeater inside UpdatePanel, need to create PostBackTrigger UpdatePanel上的AsyncPostBackTrigger和PostBackTrigger之间的区别? - Difference between AsyncPostBackTrigger and PostBackTrigger on UpdatePanel? 在Updatepanel内部触发PostBackTrigger时,scriptmanager.registerstartupscript不起作用。 为什么? - scriptmanager.registerstartupscript not working when PostBackTrigger fire inside updatepanel. why? 无法在 UpdatePanel 中下载文件 - Cannot Download file in UpdatePanel 如何从 ASP 中的 UpdatePanel 内的内容页面下载文件 - How to download a file from a content page inside UpdatePanel in ASP UpdatePanel-具有相同控件但事件不同的asyncpostbacktrigger和postbacktrigger - UpdatePanel - asyncpostbacktrigger and postbacktrigger with same control but different events 使用UpdatePanel从UserControl下载文件 - Download a file from UserControl with UpdatePanel 用于GridView内FileUpload功能的PostBackTrigger - PostBackTrigger for FileUpload functionality inside a GridView 带有 PostBackTrigger 的 UpdatePanel 不会更新其外部的标签并在回发后继续 - UpdatePanel with PostBackTrigger does not update the Label outside it and carry on after postbacks
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM