ASP.NET button that performs a server-side action, returns a file to download, and plays nicely with an UpdateProgress... In a single request -
I have an ASP.Net page (using ASP.NET AJAX and TeleRC components) which is a data table and A provides option to download data in CSV format.
I have a requirement that a button allows the user to download data sets. I have a system that is working on a solution basis for me
My ASPX looks like this:
& lt; Asp: button id = "export csb button" runat = "server" text = "download on csv / excel" onclic = "exportcashbutton link" "OnClientClick =" aspnetForm.target = '_blank'; " Then for exportCsvButton_Clicked in my codebehind, I do something like this:
byte [] csvBytes = someLongOperation (); session [ EXPORTED_SESSION_KEY] = CSVites; response. Redirect ("myexportpage.aspx", true);
In the end, in my 'myexportpage' codebehind, I am doing this:
< Pre> Secure Zero Page_load (Object Sender, EventArgs e) {Response.Clear (); Response.ClearHeaders (); Response.ClearContent (); Response.AppendHeader ("Content-nature", "Attachment; File name = "+" File.csv "); Response.ContentType =" text / csv "; Response.AddHeader (" Pigma "," Public Response.Flush (); Response.End ();}
This is actually a binarywidth (session [other page. EXPORTED_SESSION_KEY] byte [] Works well enough. When I click on the 'export to CSV' button, the update of the page progresses kicks in and my loading overlay appears (this is a CSS div that is visible when covering the window Does). It can take some time based on the data set (potentially several minutes), on which I am getting window popup with my file. I can save or open the file in my browser and when I save the file I can continue on the page with my export button Cool
My only problem is that the update progress never goes away - postback is not complete (because I am redirecting the response to the mini export page and there is no dedicated response to the postback request is?) .
I can use a very brittle solution, if need be, because this functionality does not need anywhere else in the web app for the rest of the life.
Very green mileage on AJX will not be very surprised if there is not a great solution already I can use. What I really want to save is to force the user to initiate another request to start the download (as you see on file download sites- "Your download will not start in the next 5 seconds, so just click here").
Any thoughts?
I do not think this is possible - file downloads and
my export button 2 clicks are required, but there are no page changes.
My export button has stopped the operation to generate export data, which I serialized in the user's session when this action was completed, I hid the export button and 'Your download it got ready. Click here to save the link that appears in your place on your page. This happened at the end of the event handler for all the export buttons.
When the user clicks the download link, the event handler sent the exported data to the user for it.
I chose the option to leave the download link after that until the user did not refresh the page or changed some other controls on the page that were able to export that data.
Comments
Post a Comment