i have a simple custom application which fetches records from a lists by a caml query and through an export button the user is able to get a csv file with the data.
Generally the export works fine. But after the export nothign works on the page. I mean it is no longer possible to click on buttons and no events are getting executed (button onclick event).
private void ExportToCSV(SPListItemCollection items)
{
if (items != null && items.Count > 0)
{
string attachment = "attachment; filename=export.csv";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ClearHeaders();
HttpContext.Current.Response.ClearContent();
HttpContext.Current.Response.AddHeader("content-disposition", attachment);
HttpContext.Current.Response.ContentType = "text/csv";
string columnNames = "Region;Country;Company";
HttpContext.Current.Response.Write(columnNames);
HttpContext.Current.Response.Write(Environment.NewLine);
foreach (SPListItem item in items)
{
WriteCompetitorInfoToCSV(item);
HttpContext.Current.Response.Flush();
}
HttpContext.Current.Response.End();
}
}
private void WriteCompetitorInfoToCSV(SPListItem item)
{
StringBuilder stringBuilder = new StringBuilder();
AddSemicolon(new SPFieldLookupValue(item["fielda"] as String).LookupValue, stringBuilder);
AddSemicolon(new SPFieldLookupValue(item["fieldb"] as String).LookupValue, stringBuilder);
AddSemicolon(new SPFieldLookupValue(item["fieldc"] as String).LookupValue, stringBuilder);
HttpContext.Current.Response.Write(stringBuilder.ToString());
HttpContext.Current.Response.Write(Environment.NewLine);
}
Why does this happen?