I am currently able to save a List to a CSV file on the server as in code below. However i want the ASP.NET application to prompt the user with a File Save Dialog box and save it in his client system. So i have this code in the 'Export to CSV' button click of the page which binds the list to a GridView. However, this code throws a JavaScript error at runtime in IE, copied below. What is wrong with this ? Should the Response be on a separate ASPX ?
CsvContext cc = new CsvContext();
string outputFileName = string.Format("D:\\Dashboard.csv", DateTime.Now);
cc.Write(filteredListOfPerformanceDashboardSummary, outputFileName);
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", outputFileName);
HttpContext.Current.Response.ContentType = "text/csv";
HttpContext.Current.Response.AddHeader("Pragma", "public");
HttpContext.Current.Response.Write(cc.ToString());
HttpContext.Current.Response.End();
I get this IE error
Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed
.
when i click the link it gives an error here
function Sys$WebForms$PageRequestManager$_endPostBack(error, executor, data) {
if (this._request === executor.get_webRequest()) {
this._processingRequest = false;
this._additionalInput = null;
this._request = null;
}
var handler = this._get_eventHandlerList().getHandler("endRequest");
var errorHandled = false;
if (handler) {
var eventArgs = new Sys.WebForms.EndRequestEventArgs(error, data ? data.dataItems : {}, executor);
handler(this, eventArgs);
errorHandled = eventArgs.get_errorHandled();
}
if (error && !errorHandled) {
throw error;
}
}