How to call a javascript function after a download in webforms

0

I have an aspx page with a grid and a linkbutton. When clicking on this linkbutton I call a function that locks the screen and places a loading while downloading a file on the server, after download I try to call the function to unlock the screen, but it does not call because the response has already been finalized. I tried to perform via iframe but I do not know how to send that same file to be downloaded in the iframe.

Follow my codes.

When I click on the grid linkbutton

Script code

$('#meugrid').find('a').click(function () { ForceBlock(); });

Linkbutton code in codebehind

protected void linkbtn_Click(object sender, EventArgs e)
    {
            LinkButton lb = (LinkButton)sender;

            int id = Convert.ToInt32(lb.CommandArgument);

            FileInfo arquivo = new FileInfo("meuarquivo");
            string path = @"meucaminho\";

                File.WriteAllBytes(path + arquivo.FileName, arquivo);

                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + arquivo.FileName);
                Response.AddHeader("Content-Length", arquivo.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.TransmitFile(path + arquivo.FileName);
                Response.Flush();
                Response.Close();

                HttpContext.Current.ApplicationInstance.CompleteRequest();


            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "scriptUnblock", "ForceUnblock()", true);

    }
    
asked by anonymous 10.10.2018 / 23:00

1 answer

0

I was able to solve it by creating a Generic Handler with the download code. In my page I call a function js that passes the url of that .ashx to an invisible iframe, that .ashx downloads and then on my page I call my other function to unlock the UI.

    
11.10.2018 / 14:48