Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
i am calling this webservice from jquery. objFF.FieldHtml contains html table to exoprt in excel file. objFF.FieldName is filename. now when call this web service from client side then it give an error such as {Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}.
this is my webservice

C#
[WebMethod]
    [System.Web.Script.Services.ScriptMethod(ResponseFormat = System.Web.Script.Services.ResponseFormat.Json)]
    public void ExportToExcel(FormFieldsInfo objFF)
    {
        try
        {
            //FormBuilderDataProvider.ExportToExcel(objFF);

            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ClearContent();
            HttpContext.Current.Response.ClearHeaders();

            HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + objFF.FieldName + "_" + DateTime.Now.ToString("M_dd_yyyy_H_M_s") + ".xls");
            HttpContext.Current.Response.ContentType = "text/xls";
            HttpContext.Current.Response.Write(objFF.FieldHtml);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
            //HttpContext.Current.ApplicationInstance.CompleteRequest();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }


this is my jquery function
C#
GetFormReport: function(fileName) {

                    var html = '<table><tr><th>Name</th><th>Age</th></tr><tr><td>shyam</td><td>27</td></tr><tr><td>sujan</td><td>30</td></tr><tr><td>dhrub</td><td>25</td></tr></table>';

                    var tableContent = {
                        FormFieldsInfo: { FieldHtml: html, FieldName: fileName }
                    }
                    this.config.method = "ExportToExcel";
                    this.config.url = this.config.baseURL + this.config.method;
                    this.config.data = JSON2.stringify({ "objFF": tableContent.FormFieldsInfo });
                    this.config.ajaxCallMode = 4;
                    this.ajaxCall(this.config);
                }
Posted

1 solution

Below is a small explanation and resolution to resolve this issue,


This error normally occurs when we use Response.Redirect or Server.Transfer or Response.End in your code before completing the actual process the page was doing.

In this case what you have to do is

In place of Response.End you have to use HttpContext.Current.ApplicationInstance.CompleteRequest

and in place of Response.Redirect, use the Response.Redirect ("Paganame.aspx", false);

and in place of Server.Transfer, use the Server.Execute

Please mark as the solution and vote if this solves your problem. Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900