Form Control postback

James Mosquito asked on October 21, 2020 12:36

Hi I am creating a form control and it contains a button that when clicked will create and trigger a file to download. The file download is working fine but on postback the default Kentico loading modal appears and remains - forcing you to navigate away from the page and back to it. How should I handle this?

The code I am using is included below and has been shortened for brevity:


<cms:CMSUpdatePanel ID="Panel" runat="server" UpdateMode="Conditional">
        <asp:PostBackTrigger ControlID="btnDownload" />
        <asp:Button ID="btnDownload" runat="server" Text="Download" CssClass="btn btn-default" />


public void Download_Click(object sender, EventArgs e)
    var exampleFilePath = Server.MapPath("~/example.csv");

    using (var writer = new StreamWriter(exampleFilePath))

    Response.ContentType = "text/csv";
    Response.AppendHeader("Content-Disposition", "attachment; filename=example.csv");

Thanks, James

Recent Answers

James Mosquito answered on October 22, 2020 09:27

I managed to resolve this by closing the loader using a timer in the onclick event of the button:


<asp:Button ID="btnDownload" runat="server" Text="Download" OnClientClick="setTimeout(closeLoader, 1000);" CssClass="btn btn-default" />


<script type="text/javascript">
    function closeLoader() {
        if (window.Loader) {

It feels a little hacky so I'm open to alternative suggestions.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.