In my application I have updatepanel with few buttons. One of those button is ‘Export’ button – after clicking it user can download report to his local computer.
button is created in this way:
btnSave = new Button
{ ID = "btnSave", CausesValidation = false, Text = "Save", CommandName = CommandNames.SaveToCSV };
Controls.Add(btnSave);
ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnSave);
And after clicking it this code is executed:
string csv = GenerateReport();
Page.Response.Clear();
Page.Response.Buffer = true;
Page.Response.ContentType = "text/csv";
Page.Response.AppendHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
Page.Response.Write(csv);
Page.Response.End();
Downloading works corectly even in update panel. My problem is that after first click on Export button all buttons stop works – I have page that doesn’t send anything to server – checked in Fiddler (but client javascrpts works correctly).
Does anyone know how to resolve this problem? Maybe there is another way of downloading data from updatepanel (I cannot remove this button from update panel).
I’m not sure why this happens, but a quick workaround could be to change the download button to a simple href with target=_blank, and move the csv generation code to a dedicated page\http-handler