{Text =无法评估表达式,因为代码已优化或本机框位于调用堆栈之上。} [英] {Text = Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.}
问题描述
您好b $ b
我有一个导出到Excel的按钮。它工作正常,直到它得到Response.End();
之后我得到一个错误说{Text =无法评估表达式,因为代码已优化或本机框架位于顶部调用堆栈。}之后弹出一个窗口,询问您是要保存还是查看文件。它显示它是一个Excel文件,但是一旦我查看它,它就会在Visual Studio 2009中打开。有关如何解决此问题的任何帮助将不胜感激,这是我目前使用的代码:
Hi
I have a button that Exports to Excel. It works fine and all until it get's to the Response.End();
After that I get an error saying {Text = Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack.} After that the a window pops up that asks if you want to save or view the file. It shows that it's a Excel file, but as soon as I view it, it opens in Visual Studio 2009. Any help on how to solve this problem would be appreciated, here is the code I am currently using:
public override void VerifyRenderingInServerForm(Control control)
{
//Verifies that the control is rendered
}
protected void btnExportToExcel_Click(object sender, EventArgs e)
{
try
{
if (gvCustomData.Rows.Count > 0)
{
Response.Clear();
Response.Buffer = true;
Response.ContentType = "application/vnd.ms-excel";
// Response.ContentType ="application/text";
Response.AddHeader("Content-Disposition", "attachment;CustomData.xls");
Response.Charset = "";
this.EnableViewState = false;
System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
System.Web.UI.Html32TextWriter oHtmlTextWriter = new System.Web.UI.Html32TextWriter(oStringWriter);
gvCustomData.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
}
}
catch (Exception ex)
{
Adhoc.msg(this, "Error: " + ex.Message);
}
}
推荐答案
您可以在此链接中找到一些答案。
http://support.microsoft.com/kb/312629/en-us [ ^ ]
You may find some answers in this link.
http://support.microsoft.com/kb/312629/en-us[^]
只需删除它可以使用的Try Catch Block。
Just Remove the Try Catch Block it will work.
这篇关于{Text =无法评估表达式,因为代码已优化或本机框位于调用堆栈之上。}的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!