Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7723873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:33:10+00:00 2026-06-01T04:33:10+00:00

I am using the code below to download an Excel file. Once the Response.End()

  • 0

I am using the code below to download an Excel file. Once the Response.End() call runs, I want to close window. However, this isn’t happening. Please see the code I have so far below.

'Write it back to the client

   Dim filename As String = "FullExtract_" & Now.Year.ToString & Now.Month.ToString & Now.Day.ToString & ".xlsx"
   Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
   Response.AddHeader("content-disposition", "attachment;  filename=" & filename)
   Response.BinaryWrite(pck.GetAsByteArray())
   Response.End()
   'cursor not reaching to below code   
   Page.ClientScript.RegisterStartupScript(Me.GetType(), "closedownload", "JavaScript:window.close(); return false;")

How do I close the window?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:33:12+00:00Added an answer on June 1, 2026 at 4:33 am

    Don’t call Response.End. That throws a ThreadAbortException, which will cause all kinds of nasty things. Also, this exception is what is preventing your Page.ClientScript after the Response.End not to fire. So just remove the Response.End. Its no longer needed and a hold over from the old classic ASP days.

    EDIT: You can’t close the window like that; when you send the file for download, it should open a file save prompt on the users OS, and the file will download. The html RegisterStartupScript would generate would end up as part of the file download I’d think. You should probably have the page which the button or link that triggers the download open a new window using target=”_blank” or via javascript, that window would close automatically or not even opene depending on the browser.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the code below to download this XML file : private async static
Using the code below, I want to keep the same menu div opened in
Using the code below each image download) file_get_contents() ) takes on average 8-15 seconds.....
I am using the code below to download multiple attachments from a TFS server:
I am using the code below in asyn task to download a bitmap to
I'm using the below code to listen for change events of a file i
As of right now I'm using this code below to download files to get
I'm downloading files using the below code. Can I create folders dynamically and download
I'm using the code below to create a folder and then download the assocated
Using the code below, I am attempting to fill a Canvas with UIElements and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.