I want to do an onclick function that downloads an excel file that is also created when a user clicks a button, so I found this function that I am using for the onclick
public void CreateExcel(object sender, EventArgs e)
{
DataTable dt;
dt = Database.Get_All_Approval_Table_Grouped
string attachment = "attachment; filename=example.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/vnd.ms-excel";
string tab = "";
foreach (DataColumn dc in dt.Columns)
{
Response.Write(tab + dc.ColumnName);
tab = "\t";
}
Response.Write("\n");
int i;
foreach (DataRow dr in dt.Rows)
{
tab = "";
for (i = 0; i < dt.Columns.Count; i++)
{
Response.Write(tab + dr[i].ToString());
tab = "\t";
}
Response.Write("\n");
}
Response.End();
}
The following is the response I receive:
Line: 885
Error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed.