How to call a javascript function after a webforms download

Asked

Viewed 91 times

0

I have an aspx page with a grid and a linkbutton. When clicking on this linkbutton I call a function that hangs the screen and places a loading while downloading a file on the server, after the download I try to call the function to unlock the screen, but it does not call because the Answer has already been completed. tried to perform via iframe but don’t know how to send that same file to be downloaded in 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);

    }

1 answer

0

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.