locked
Update Panel And Response.End RRS feed

  • Question

  • User1310682911 posted

    Hi, I'm relatively new to asp.net and I've encountered a 
    problem, I have a button that clicks on a file and generates another output,
    the problem is that when I click I want to show a simple gif of loading something
    that I have already achieved but the problem is that the response.
    end that the user sends the file to download is not done, I have investigated and so far
    I only do one thing or another, someone has an idea of ​​how to do that?
    Friday, December 21, 2018 8:30 PM

All replies

  • User-893317190 posted

    Hi Fernando SZ,

    It is not clear about how you write your code.

    Could you show your whole code about downloading the file?

    From  your title, it seems your are using update panel to deal with files, the problem may be caused by this.

    Please try to change the async mode of update panel to see whether the problem occurs.

     <form id="form1" runat="server">
            <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" >
                <ContentTemplate >
                       <asp:Button runat="server" Text="Button" OnClick="Unnamed_Click" ID="btn" /> 
                </ContentTemplate>
            <Triggers >
                
                <asp:PostBackTrigger ControlID="btn"   />
                
            </Triggers>
            </asp:UpdatePanel>
            
        </form>

    Please set the ControlId to the id of the button.

    My code behind.

     protected void Unnamed_Click(object sender, EventArgs e)
            {
                Response.Clear();
    
                Response.AddHeader("content-disposition", "attachment;filename=yourfilename.txt");
    
                Response.WriteFile(Server.MapPath("/ajaxUpdatePanel/ajaxWebForm.aspx"));
    
                Response.End();
            }

    If it doesn't meet your requirement, please post your related code to let us reproduce your problem.

    Best regards,

    Ackerly Xu

    Monday, December 24, 2018 1:59 AM