asp.net无法在response.binarywrite之后继续 [英] asp.net can't continue after response.binarywrite

查看:159
本文介绍了asp.net无法在response.binarywrite之后继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码可以成功地将pdf写入客户端.问题是执行此操作后我无法获得任何代码.这是向导的最后一步,尽管将其放在ActiveStepChanged处理程序中,也从未进入确认/最终页面.

I have the following code which successfully writes a pdf to the client. The problem is that I can't get any code after this to execute. It's the last step of a wizard, and despite putting this in the ActiveStepChanged handler, it never makes it to the confirmation/final page.

                    Response.Clear()
                Response.ContentType = Nothing
                Response.AddHeader("content-disposition", "attachment; filename=" & FileName)
                Response.BinaryWrite(data)
                Response.Flush()

基本上,有一个复选框供用户在单击完成"按钮时检查是否要下载文件.我不想有一个单独的按钮来下载文件,因为众所周知,用户会感到困惑,并认为通过按下下载按钮,他们已经完成了必要的步骤,而从未完成其应用程序(我们在谈论非计算机识字用户).这样就可以了,除了他们选择该选项时并没有进入确认步骤.

Basically, there's a checkbox that the user checks if they want to download the file when they hit the Finish button. I don't want to have a separate button to download the file because users have been known to get confused and think that by pressing the download button that they've completed the necessary steps and never complete their application (we're talking about non computer literate users here). So it all works, except it doesn't make it to the confirmation step when they select that option.

如何确保下载文件后继续进行处理?

How can I ensure that processing continues after downloading the file?

推荐答案

我自己想到了这个.基本上,我将response.binarywrite代码(在op中列出)放置在其自己的空Web窗体后面的代码中.然后,我调用,然后使用ScriptManager.RegisterClientScriptBlock中的javascript openwindow函数将其打开.

I figured this one out myself. Basically, I placed the response.binarywrite code (listed in op) in the code behind of its own empty webform. I then call then use the javascript openwindow function in ScriptManager.RegisterClientScriptBlock to open it.

原始页中的代码:

            Me.Session("PrintApplication") = data
            Me.Session("PrintApplicationFileName") = FileName

            ScriptManager.RegisterClientScriptBlock(Me, Me.GetType, "PrintReport", "window.open('PrintApplication.aspx');", True)

PrintApplication.aspx中的代码:

Code in PrintApplication.aspx:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    If Me.Session("PrintApplicationFileName") <> Nothing Then
        Dim data As Byte() = Me.Session("PrintApplication")
        Dim FileName As String = Me.Session("PrintApplicationFileName")

        Me.Session("PrintApplication") = Nothing
        Me.Session("PrintApplicationFileName") = Nothing
        Response.Clear()
        Response.ContentType = Nothing
        Response.AddHeader("content-disposition", "attachment; filename=" & FileName)
        Response.BinaryWrite(data)
        Response.Flush()
        Response.End()

    End If

End Sub

完美运行

这篇关于asp.net无法在response.binarywrite之后继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆