Note that there are some explanatory texts on larger screens.

plurals
  1. POExporting HTML Table to Excel via Page Method
    primarykey
    data
    text
    <p>I have the following code on the client side for retrieving data from the HTML Table and then send it to the server through the page method:</p> <pre><code>function dtExportToCSV(dataTable) { var elements = dtDataToJSON(dataTable); var headers = dtHeadersToJSON(tableSelector); jQuery.ajax({ type: "POST", url: "Report.aspx/exportToCSV", data: "{'elements': " + elements + ", 'headers': " + JSON.stringify(headers) + "}", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { if (msg.d) { } else { } }, error: function(xhr, ajaxOptions, thrownError) { alert(xhr.statusText); } }); } </code></pre> <p>Then I use the following code on the server side, to export the retrieved data to CSV file.</p> <pre><code>/// &lt;summary&gt; /// /// &lt;/summary&gt; /// &lt;param name="elements"&gt;&lt;/param&gt; /// &lt;param name="headers"&gt;&lt;/param&gt; [WebMethod(EnableSession=true)] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static bool exportToCSV(List&lt;object&gt; elements, List&lt;string&gt; headers) { try { string attachmentType = "attachment; filename=ShortageReport.csv"; HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ClearHeaders(); HttpContext.Current.Response.ClearContent(); HttpContext.Current.Response.AddHeader("content-disposition", attachmentType); HttpContext.Current.Response.ContentType = "text/csv"; HttpContext.Current.Response.AddHeader("Pragma", "public"); writeHeadersInfo(headers); HttpContext.Current.Response.End(); } catch (Exception ex) { Console.WriteLine(ex.Message); } return false; } </code></pre> <p>But I get this expcetion: <strong><em>Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.</em></strong></p> <p>Does anyone knows how to handle this issue?</p> <p>Any help would be highly appreciated! Thanks in Advance!</p> <p>~ Eder Quiñones</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload