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 337073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:18:06+00:00 2026-05-12T10:18:06+00:00

I have an ASP.NET page where I’m generating an Excel spreadsheet and sending that

  • 0

I have an ASP.NET page where I’m generating an Excel spreadsheet and sending that in the response (content-disposition header). That part works great, but I have a button that never becomes re-enabled because the original page isn’t part of the response.

Here’s the function I’m using:

Public Shared Sub WriteToResponse(ByVal theWorkBook As Workbook, ByVal FileName As String, ByVal resp As HttpResponse)
    Dim theStream As New System.IO.MemoryStream()
    theWorkBook.Save(theStream)

    Dim byteArr As Byte() = DirectCast(Array.CreateInstance(GetType(Byte), theStream.Length), Byte())

    theStream.Position = 0
    theStream.Read(byteArr, 0, CInt(theStream.Length))
    theStream.Close()

    resp.Clear()
    resp.AddHeader("content-disposition", "attachment; filename=" & FileName)
    resp.BinaryWrite(byteArr)
    resp.End()
End Sub

I tried not clearing the response and using AppendHeader instead of AddHeader, but the response still contains only the file.

What am I missing? Do I need to use a different header? I found this unanswered question on the ASP.NET forums; sounds like my problem.

  • 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-05-12T10:18:06+00:00Added an answer on May 12, 2026 at 10:18 am

    You can’t. You can fake the behaviour by opening a popup on clicking the button and have the popup serve up the file and posting back the page from the javascript. But in this manner you are effectively creating 2 requests with 2 responses.

    update: if you want to disable the button when they start the download and enable it as soon as the download starts you can’t really do this but you could use some trickery to make it appear like that. When they click on the download button use some javascript to disable the button and to create the popup that kicks off the file streaming. When the filestreaming function (WriteToResponse) returns set some value in the users session. In the mean time have the original page poll the server using AJAX to see if the session value is set. If it’s set re-enable the button and set to the value to empty or false again (so this works a 2nd time). But this seems like a whole lot of tricks.

    but I think in this case the cure is worse then the problem. I assume you want this because generating the file takes a while and you don’t want users to reset the flow by pressing the button impatiently while the file is being prepared. To accomplish this I would just show a popup message in the page on button press saying something like “Your download is being prepared. This might take a minute. Thank you for your patience. (click to dismiss this message)”

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

Sidebar

Related Questions

I have a ASP.NET page with an asp:button that is not visible. I can't
I have an ASP.Net page that will be hosted on a couple different servers,
I have an ASP.NET page that gets a list of game server ip addresses
I have an asp.net page with c# code-behind. I have an event that is
I have an ASP.NET page that I want to be able to generate and
I have an ASP.NET page that uses a MasterPage. I have a public bool
I have a ASP.NET page that takes some key, value data and a HttpFileCollection
I have an ASP.Net page that has a script:# var Show; $(document).ready(function () {
I have an asp.net page that is trying to access a SSRS 2008 ReportServer
i have asp.net page that is opened inside an iframe. How to redirect to

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.