Activate button on ASP.NET once HttpResponse is received

After clicking a button on my ASP.NET page, it gets disabled to prevent double clicking and triggers the following function:

Private Sub ExportToExcel(ByVal nameReport As String, ByVal wControl As GridView, ByVal sTitle As String)
    Dim responsePage As HttpResponse = Response
    Dim sw As New StringWriter()
    Dim htw As New HtmlTextWriter(sw)
    Dim pageToRender As New Page()
    Dim form As New HtmlForm()

    wControl.AllowPaging = False
    wControl.EnableViewState = False
    wControl.DataSource = GetDataSource(False)
    wControl.DataBind()

    wControl.Caption = "<strong>" + sTitle + "</strong>"
    form.Controls.Add(wControl)
    pageToRender.Controls.Add(form)
    responsePage.Clear()
    responsePage.Buffer = True
    responsePage.ContentType = "application/vnd.ms-excel"
    responsePage.AddHeader("Content-Disposition", "attachment;filename=" & nameReport)
    responsePage.Charset = "UTF-8"
    responsePage.ContentEncoding = Encoding.Default
    pageToRender.RenderControl(htw)
    responsePage.Write(sw.ToString())
    responsePage.End()
End Sub

After the data is exported to Excel, I need to re-enable the button on the client-side. How can I achieve this?

Answer №1

When the Response.End() function is called, it abruptly stops the current thread and transfers control to Application_EndRequest. At this point, there is limited action that can be taken. For further information, you may want to refer to this post, which suggests a workaround involving iframes.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular Digest Loop for Dynamic Photo Grid Styling

I have a special filter that alters the objects being filtered. However, when I apply ng-style="item.gridSize", it triggers my custom grid algorithm. This algorithm was adapted for my requirements from a source found at this link. angular.module("custom.m ...

Are there any security concerns involved in creating a game using a combination of JavaScript, Electron, and Three.js?

I'm not looking to create anything on the scale of an MMORPG, just a small game similar to Faster Than Light. Is there a way to protect against cheat engine or prevent users from running their own JavaScript in the game, considering anyone can access ...

Tips on maintaining the color of the favorite / unfavorite button even after refreshing the page

I am currently developing a Laravel project that allows users to favorite and unfavorite books. When a user clicks on the favorite button, the color changes to red. If clicked again, the color reverts back to gray. The database successfully updates without ...

How to Extract a URL from an Anchor Tag without an HREF Attribute Using Selenium

How can I make a link, which normally opens in a new window when clicked, open in the current window instead? The link does not have an href attribute, only an id and a class. For example: <a id="thisLink" class="linkOut">someLinkText</a> I r ...

What is the best way to change a string that represents an array into an actual array?

Experimenting with something new... Imagine I have the following HTML code: <div id="helloworld" call="chart" width="350" height="200" value="[[4, 8, 1, 88, 21],[45, 2, 67, 11, 9],[33, 4, 63, 4, 1]]" label="['test1', ...

How can I ensure that an item stays in place within a vertically sortable list using Dndkit? (I am also considering alternative drag-and-drop libraries)

Let's say for instance that 5 was marked as frozen. If 4 was then moved below 6, the change in arrangement would be as follows: before: https://i.sstatic.net/iVZFtAmj.png after: https://i.sstatic.net/tCq09Qgy.png My current approach involves us ...

Is there a way to adjust the quantity individually, both increasing and decreasing as needed?

I am currently working on implementing a shopping cart feature using pure JS that allows users to increase and decrease the quantity of items. When the + or - button is clicked, both items in the shopping cart will be affected simultaneously if there are 2 ...

Node -- error encountered: options parameter must be of type object

Encountering a frustrating issue with the error message TypeError: options must be an object. Currently delving into the State example in Chapter 4 of Node.js Design Patterns. Initially assumed it was a mistake on my end, but even after testing the file w ...

What is the best way to adjust the CSS of an element within the #shadow-root (open) in web development?

When dealing with a "#shadow-root (open)" element, it appears that manipulating the style using only CSS is not feasible. The shadow-root was generated by a third-party JavaScript script and displays an element as an overlay on the page that I am trying to ...

Converting units to rem dynamically in CSS: a comprehensive guide

Hey there, I'm currently trying to dynamically convert units into rem in CSS and facing some issues. I have set the root font-size as 23px The current font-size is 16px The expected result should be 16 / 23 => 0.695rem Question: I am looking for ...

What steps can be taken to provide accurate information in the absence of ImageData?

Utilizing a JS library to convert a raster image into a vector, I encountered an issue where the library returned a fill of solid color instead of the desired outcome. I suspect that the problem lies within the ArrayBuffer. The process of loading an imag ...

What could be the reason for this function failing to calculate the mean of a set of data points?

I'm facing a challenge with this beginner problem. "A task for you: Calculate the average score of a class whose test scores have been graded by a teacher. Your mission is to complete the getAverage function, which receives an array of test sco ...

ng-html-bind for a label with a checkbox

Currently, I have a view that uses the standard bootstrap layout for checkboxes. In this layout, the input is located within the label tag. <div class="checkbox"> <label ng-bind-html="vm.trustedHtml"> <input type="checkbox" ng- ...

Transform JSON into an Array and generate a new Array from a collection of Arrays

I'm struggling with generating a table in Angular2 from JSON data because I need to pivot the information, but my usual method doesn't seem to work for this scenario. Below is an excerpt of the JSON data I am working with: [ { "ValueDate" ...

Exploring the functionality of dynamic component imports in jest testing

Under a specific condition, I dynamically imported a component and stored it in an object property. Then, I displayed it in the template using vue <component :is="">. Everything is functioning correctly at the component level. However, I am ...

There appears to be an issue with reading the property 'toLowerCase' of an undefined element, and I'm having trouble identifying the error

The variables I have initialized (globally): var audio; var LANGUAGE; var audioArray; var MEDIAARRAY; var WORDS; var SOUNDARRAY; This specific line is causing the error: var audioId = MEDIAARRAY.audio.lowercase.indexOf(exObject['exerciseGetWordInpu ...

Navigating to a new page once a backend function in Express has finished executing

Recently, I have been experimenting with express web servers to create a website that allows users to sign in using Discord's OAuth2 API. In order to secure sensitive information, I have been utilizing the express-session npm module to store data with ...

Tips for ensuring elements within a modal receive immediate focus when opened in Angular 2

I am relatively new to Angular JS and I am encountering some challenges with implementing a directive in Angular 2 that can manage focusing on the modal when it is opened by clicking a button. There have been similar queries in the past, with solutions pr ...

Scan the contents of the current webpage

Is there a way for a page to self-parse? My progress so far: string whatever = TwitterSpot.InnerHtml; HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(whatever); foreach("this is where I am stuck") { } To parse the page, I created a parent div ca ...

Instructions for creating a distinct click listener for each <img> element inside a table cell

Within my table, each row contains multiple columns with images as data. I successfully implemented a 'common listener' that is triggered when any image within a table row is clicked. $('#mytable tbody td img').click(function () { // ...