Using ASP.NET page: executing Javascript function upon receiving file download response from the server

I am facing a situation with my ASP.NET page where the server returns either a new page or a file for download after a request is made. I would like to display a "Processing..." message on the screen while the data is being retrieved from the server.

It's easy to call JavaScript when the user hits submit, but the page reload on Postback hides any "Processing..." indicators that are shown (such as DIVs popping up at the top of the page).

The main issue arises when the data returned by the server is a file instead of a web page. How can I detect when the server starts returning the data so that I can execute JavaScript to remove the "Processing" indicator? Is this even possible, especially when the response is of a different MIME type? In what scenarios would it be feasible?

Answer №1

There are different approaches to achieve what you're aiming for using timers and assumptions, but to truly accomplish the task as described, it's essential to continuously query the server for confirmation that the download has been completed.

One effective method would be to send the file using Response.WriteFile, and then store a flag in a database or file system to signify that the transaction is finished. Meanwhile, the client script can continuously check the server for updates, while the server response verifies the status by checking for the presence of the flag denoting that the download has taken place.

The crucial aspect here is to have precise control over the download process itself; simply redirecting to the file will not provide the necessary level of oversight. If you require further guidance on implementing any of these steps, feel free to reach out for more detailed instructions.

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

Adding Firebase Authentication to my AngularJS website

I am currently creating a school website using AngularJS. My goal is to incorporate account functionality through firebase authentication. However, I have limited experience with Javascript and find working with AngularJS and implementing firebase to be ...

Navigate to designated page upon session expiration in MVC6

Currently working on a C# MVC6 project, I am facing the challenge of redirecting to a specific page once the session expires. In my quest for a solution, I attempted implementing: public class SessionExpireAttribute : ActionFilterAttribute HttpContext ...

The system was unable to load the gRPC binary module due to its absence in the current installation

I recently developed an electron app that utilizes Firebase's real-time database. I followed a tutorial on YouTube and carefully reviewed the documentation on Firebase's website to ensure everything was set up correctly. Here is a snippet of my c ...

Error message: When using the Three.JS STL Loader, an Uncaught TypeError occurs because the property 'scale' is being called on an undefined value

I am currently loading five elements using the STL Loader in order to create a table. My goal is to use dat.gui to adjust the scale of Tabletop.STL. Here is the code snippet: <!DOCTYPE html> <html lang="en> <head> <title& ...

Styling the display of specific elements connected to a Repeater for a more polished appearance

When working in the backend, I am binding a datatable to a repeater. In the front end, my repeater setup looks like this: <asp:Repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound"> <ItemTemplate> <div cla ...

When invoked, a Javascript Object comes back empty

My code snippet: const channels = fauna.paginate(q.Match(q.Index("channels"), "true")) // Query FaunaDB database for channel list => create constant called users containing results const channelList = channels.each(function (page) { ...

The Instagram API seems to be experiencing some technical difficulties

My expertise lies primarily in HTML/CSS, with limited knowledge of using APIs and JavaScript. I have been assigned the task of utilizing an API to retrieve Instagram pictures posted by users with a specific hashtag. Here is the demo shared via JSFiddle: ...

Executing a Python script in Django and transferring its output to a JavaScript file

Getting Started with Django What I'm Looking For: 1 - Execute a Python Script 2 - Pass data to a JavaScript file I'm unsure if the sentence I've constructed is technically accurate in terms of Django. Below are the JavaScript and Python ...

Halt the execution of a function upon clicking a div element

I'm currently working on a function that needs to be stopped when a div with the class "ego" is clicked. This function toggles the visibility of the header based on the scroll position and should only run by default. Below is the code snippet: $("#e ...

Updating the state value of a variable that utilizes a custom Hook: a step-by-step guide

After watching a video by Dan Abramov, I decided to optimize my component by creating a custom Hook called useFormInput. This hook handles the state and onChange functionality for all of my form input fields. Everything was working perfectly until I neede ...

Reset input fields upon jQuery removal

Currently, I am working on a form that includes a remove function. The function is functioning correctly, but I am facing an issue where I want the field values to be cleared when the remove function is triggered. This is necessary as I am sending input va ...

``To increase a value within an array object in MongoDB with the use of nodejs, what steps should be

Within my node.js application, I have a MongoDB post model that includes an array of comments. Each comment has a "likes" field representing the number of likes it has received. I want to increment this value for each comment individually. How can I achiev ...

Submitting an AJAX request to upload an XML file and an image file simultaneously in one call

I need to send both an uploaded image and an uploaded XML file to a PHP file using a single AJAX call. I have tried using two form data instances, but I am not sure if this is the correct approach. <input type="file" class="form-control-file" name="fil ...

Customize the size of data points on your Angular 2 chart with variable

In my Angular 2 application, I am utilizing ng2-charts to create a line chart. The chart functions properly, showing a change in color when hovering over a point with the mouse. However, I want to replicate this behavior manually through code. Upon clicki ...

Can the start and stop times of the typed.js plugin be controlled for typing text?

The typed.js jQuery plugin creates the illusion of text being automatically typed on screen by a robot. Despite researching the resources related to this plugin, I have not come across any information on how to control the starting and stopping of the typi ...

Error: The validation process for schema[parameter] cannot be completed as the function validateAsync is not

While attempting to develop an API using express, I encountered the error mentioned above. Despite referring to various GitHub resources with solutions to similar issues, none of them seem to resolve my problem. Below is the code snippet: API: http://loca ...

Creating a Class level Route in asp.net that utilizes a variable

Can you create a class-level Route with a variable at the end? For example: [Route("api/{carType}")] public class CarController : Controller { ..rest of class } If this is possible, how would you go about accessing that variable? Or am I approaching ...

Integrate a post AJAX call into an Angular service for seamless functionality

I have come across an interesting scenario where I have to integrate old ajax code into a new Angular 10 application as per project requirements. Is it possible to directly run the existing ajax calls in the Angular service? Or, is there any node module ...

How can I change the transparency of a CSS background color using JavaScript?

I have a question about CSS: .class1 { background: #fff } Now, I need to achieve the following: .class2 { background: rgba(255,0,0,0.5) }; Is there a way to use JavaScript only to change the background property of .class1 and give it an opacity of 0.5? ...

Setting up a new folder in the internal storage within a React Native Expo environment

In my React Native Expo project, I am utilizing two functions to store data in a JSON file and then save the file to internal storage. However, the code currently asks for permission to store inside a chosen folder, but does not create the "ProjectName" fo ...