Enable button after writing file in response

There are many similar questions, but there is still no clear answer that solves the problem by taking some action after writing the thread for the answer.

I have the following situation:

At the click of a button, I generate some excel file, which I am going to write in response, allowing the user to load the generated file. Imidietly after clicking a button, I turn it off to prevent this button from double-clicking. In the page-Load event handler, I have the following code:

 GenerateBTN.Attributes.Add("onclick", "this.disabled=true;" + ClientScript.GetPostBackEventReference(GenerateBTN, "").ToString());

After the Page_Load EventHandler, the GenerateBTN_Click handler executes the code needed to generate the file and at the end of this method (handler) I reply to the generated file using the following code:

Response.Clear();
Response.ContentType = "application/octet-stream";                
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
Response.WriteFile(@"C:\Reports\" + filename);
Response.End();    

" ", , , GenerateBTN . afer ? , afer , , ?

+3
3

IFrame . IFrame Javascript , IFrame . , .

, ​​ , , .

, Download.aspx, querystring. , - , .

Download.aspx

  using System.IO;
    protected void Page_Load(object sender, EventArgs e)
    {
        string FileName = Server.UrlDecode(Request.Params["FileName"]);  //Example: "MyFile.txt"

        Response.AppendHeader("Content-Type", "application/force-download");
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileName);
        Response.WriteFile(@"C:\MyFolder\" + FileName);
    }

, - "Download.aspx? FileName = MyFile.txt"

, , , querystring , . ASPX , , , ( ) / , . .

IFrame, 100%, , , , - : : http://sykari.net/stuff/iframe.

+1

UpdatePanel, .

0

IFrame . IFrame Javascript , IFrame - . , .

, , , .

... ...
.txt iframe? , -?

txt iframe , , iframe.

To load files in an iframe, I used the following code:

HiddenFrame.Attributes["src"] = /GeneratedFiles/ + "test.zip";

You can see that I had to use a relative path, and my file should be included in the virtual folder of the web application.

What is the best javascript (jquery) event handler (function) to determine when an iframe has finished loading? I used the jquery function:

 $("#ctl00_ContentPlaceHolder1_HiddenFrame").ready(function () {

        if ($("#ctl00_ContentPlaceHolder1_HiddenFrame").attr('src') != '') {

            $('#ctl00_ContentPlaceHolder1_GenerateSapFilesBTN').removeAttr("disabled");
        }
    });

But it seems that the button is activated before the "Save As" dialog appears. Is it possible to solve this problem with this type of eventHandler or do I need to use some other function ...

0
source

All Articles