Well, I did it with an iframe
this is a modified ajax function call
function GenerateExcel() { var ResultTable = jQuery('<div/>').append(jQuery('<table/>').append($('.hDivBox').find('thead').clone()).append($('.bDiv').find('tbody').clone())); var list = [$(ResultTable).html()]; var jsonText = JSON.stringify({ list: list }); $.ajax({ type: "POST", url: "GenerateMatrix.aspx/GenerateExcel", data: jsonText, contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { if (isNaN(response.d) == false) { $('#iframe').attr('src', 'GenerateMatrix.aspx?ExcelReportId=' + response.d); $('#iframe').load(); } else { alert(response.d); } }, failure: function (response) { alert(response.d); } }); }
and this is the constructive part
<iframe id="iframe" style="display:none;"></iframe>
on page loading my code is as follows
Response.AppendHeader("content-disposition", "attachment;filename=FileEName.xls"); Response.Charset = ""; Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.ContentType = "application/vnd.ms-excel"; Response.Write(tableHtml); Response.End();
rahul
source share