Link to home
Start Free TrialLog in
Avatar of anders_dotnet
anders_dotnet

asked on

Response.WriteFile inside UpdatePanel

When I download file using Response.WriteFile inside UpdatePanel, I will get "Sys.WebForms.PageRequestManagerParseErrorException"

How can I avoid of the ParseErrorException using Response.WriteFile or Response.TransmitFile? I need to download some files and I don't want to use links.

Thanks in advance!
ASPX:
    <img src="loading.gif" />
    <asp:Button ID="btnSelectName" runat="server" Text="Select name of the picture" 
        onclick="btnSelectName_Click" />   
    <asp:UpdatePanel ID="UpdatePanel1" runat="server" Visible ="false">
        <ContentTemplate>
            <asp:TextBox ID="tbName" runat="server" Text="loading"/>
            <asp:Button ID="btnDownload" runat="server" Text="Download" 
                onclick="btnDownload_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>
 
ASPX.CS:
    protected void btnSelectName_Click(object sender, EventArgs e)
    {
        UpdatePanel1.Visible = true;
    }
    protected void btnDownload_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.ContentType = "image/GIF";
        Response.AppendHeader("content-disposition", "attachment;filename=" + tbName.Text + ".gif");
        //Response.TransmitFile("loading.gif");
        Response.WriteFile("loading.gif");
        Response.End();
    }

Open in new window

Avatar of davesgonebananas
davesgonebananas
Flag of United Kingdom of Great Britain and Northern Ireland image

Not quite sure what you are trying to achieve here.  If you wish to display a loading animation you should check out the UpdateProgress control.  
    <asp:UpdateProgress ID="progress1" runat="server">
        <ProgressTemplate>
        
            <div class="progress">
                <img src="loading.gif" /> 
                Loading...
            </div>
        
        </ProgressTemplate>
    </asp:UpdateProgress> 

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of davesgonebananas
davesgonebananas
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of emsysindia
emsysindia

OK working fine.
However, what if I have more than one Control.
I mean, there are 3 buttons, when they clicked Post back should happen.
Any solution for this Please?