So I have a button inside my gridview. If the user clicks on the button a rowcommand is send and a pdf file is downloaded / written to the response.
Code
HttpResponse httpResponse = Response;
httpResponse.Clear();
httpResponse.ContentType = "application/pdf";
httpResponse.AddHeader("content-disposition", $"attachment;filename={rowData.Pod.fileName}");
httpResponse.Output.Write(bytes);
Response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest();
For some reason I always get Server cannot set content type after HTTP headers have been sent.
when tried to download the file. Now the gridview is in a updatepanel but that should not be a problem since other buttons for downloading work.
I have also tried to send the buffer to true before I did the file download but that did not change it.
EDIT
The problem was that there was still an async postback that I had setup on the 'selectedindexchanged' of the gridview to display a modal. Is there any way I can work around this? When I change the trigger the whole page reloads before showing the modal and also resprings. The file downloads after changing it to postback instead of asyncpostback