In Asp.net, clicking a button, how to open the download dialog, and then redirect the user to another page?

I have a button. When the user clicks on it, I want to call the download dialog, and then redirect the user to another page.

However, I am having problems loading and redirecting to work together. As soon as the download dialog appears, the rest of the code completes:

Sub DisplayDownloadDialog(ByVal filepath As String)
    Dim filename As String = Path.GetFileName(filepath)
    Response.ContentType = "application/octet-stream"
    Response.AddHeader("Content-Disposition", "attachment; filename=""" & filename & """")
    Response.WriteFile(filepath)
End Sub

I tried adding an update to the header, but it still doesn't work. I also tried javascript (but not using window.open ... as some browsers block this), but I can't get the redirect to work.

Any ideas? I really appreciate the help.

0
source share
2 answers

Response.WriteFile(filepath), Redirect

:

OnClientClick event, using windows.open(), .aspx, "download.aspx". postback , .

"download.aspx" .

, ,

0

,

  • Content.aspx β†’
  • .aspx β†’ , , ..
  • Download.aspx β†’ .

Content.aspx

/ / btnDownload Content.aspx

protected void Page_Load(object sender, EventArgs e)
    {

        btnDownload.Attributes.Add("onclick", "Javascript:GotoDownloadPage();return    
        false;");

    }

script Content.aspx

    <script type="text/javascript" language="javascript">

   function GotoDownloadPage()
    {
        window.location = "Thanks.aspx";
        return false;
    }
    </script>

Thanks.aspx

protected void Page_Load(object sender, EventArgs e)
    {

            if (!IsPostBack)
            {
                ScriptManager.RegisterStartupScript(Page, GetType(), "Redirect", 
                "<script>GotoDownloadPage()</script>", false);
            }

    }

script Thanks.aspx

 <script type="text/javascript" language="javascript">

   function GotoDownloadPage()
    {
        window.location = "Download.aspx";
        return false;
    }
    </script>

Download.aspx

, .

0

All Articles