Can someone help me,
I'm trying to do an export to excel module and I have this code for he export:
HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=exportTest.xls");
        HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
        HttpContext.Current.Response.Output.Write(excelExport);
        HttpContext.Current.ApplicationInstance.CompleteRequest();
to relate to my question, when I put this block of code to a webmethod invoked by jquery through ajax, it just gives me back the string to export in a message popup, while when I put this block of code into a click method for an asp button control (e.g. ExcelExportButton_Click) it works.
Not working code:
[WebMethod]
    public static void ExportReportsTableToExcel(string ExportReport)
    {
        string excelExport = "a string to export to excel";
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=exportTest.xls");
        HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
        HttpContext.Current.Response.Output.Write(excelExport);
        HttpContext.Current.ApplicationInstance.CompleteRequest();
    }
Working code:
protected void ExportReportButton_Click(object sender, EventArgs e)
    {
        string excelExport = "a string to export to excel";
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=exportTest.xls");
        HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
        HttpContext.Current.Response.Output.Write(excelExport);
        HttpContext.Current.ApplicationInstance.CompleteRequest();
    }
Please, don't mind the sample string.
 
     
    