0

There is a web form which perform the downloading functionality.When user click on the button it become disable first(Using JS OnClientClick method) and then downloads(Implementation in OnClick method in code behind) the relevant file after triggering the button click.I want to enable the button again after completion of the download.

Previously this was worked fine using the Cookies(Added a cookie there in code behind and continuously read it from JS).But I enabled secure cookie mechanism and now it won't disable the button.

Any alternative mechanism to get the button enable ?

Nothing worked as it running when Post Back of the page

//aspx page
<asp:Button ID="btn" runat="server" Text="Download" UseSubmitBehavior="false"
                OnClientClick="Download(this)" OnClick="btn_Click" />
function Download(element) {
            element.disabled = true; //button become disable
}
//codebehind
protected void btn_Click(object sender, EventArgs e)
        {
                var data = getData();
                Response.AddHeader("Content-Length", userDataText.Length.ToString());
                Response.ContentType = "text/csv";
                Response.AppendHeader("content-disposition", string.Format("attachment;filename=\"{0}\"", "download_file"));

                Response.Write(data);
                Response.Flush();
                Response.End();
}

I expect to disable the button after downloading the csv file.Solution should not be depend on cookies.But actual doesn't do such functionality.

LahiruD
  • 93
  • 1
  • 12
  • 1
    Your problem is the `Response.End()`. It stops any subsequent code. See [https://stackoverflow.com/questions/16731745](https://stackoverflow.com/questions/16731745/how-to-make-code-execute-after-response-end). – Bobney Jun 05 '19 at 11:50
  • Thank you.Also I changed the implementation to check the status through ajax call and placing a web method inside. Instead of cookie I used sessions and it worked. – LahiruD Jun 06 '19 at 04:06

0 Answers0