2017-01-18 23 views
0

我使用带有Gridview的UpdatePanel。计时器正在检查Gridview中的一些内容。在GridView我产生列查看上传:背后UpdatePanel中的错误:无法评估表达式,因为代码已经过优化或本机框架位于调用堆栈之上

<asp:TemplateField HeaderText="Zeichnung" ItemStyle-HorizontalAlign="Center"> 

代码:

ImageButton ibtn = new ImageButton(); 
ibtn.CommandArgument = Upload; 
ibtn.Click += btn_clicked; 
ibtn.ImageUrl = "~/images/download.png"; 
ibtn.ToolTip = "Zeichnung öffnen"; 
gvr.Cells[20].Controls.Add(ibtn); 

单击该按钮开始下载:

Response.ClearHeaders(); 
Response.ContentType = "application/pdf"; 
Response.Clear(); 
Response.AppendHeader("Content-Disposition", "attachment;Filename=" + Upload); 
Response.TransmitFile(Page.MapPath("App_data/OPL/Upload/" + Upload)); 
Response.End(); 

所有的工作罚款,直到我把GridView到UpdatePanel。现在,它引发错误:

Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack

我试着用HttpContext.Current.ApplicationInstance.CompleteRequest();但没有任何改变,以取代Response.End()

正如这里写的(question)它的回发问题。解决方案似乎是

protected void Page_Load(object sender, EventArgs e) { 
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page); 
scriptManager.RegisterPostBackControl(this.btnExcelExport); 
//Further code goes here.... 
} 

但我不能添加此代码,因为该按钮生成,并没有在gridview中给出。我试图添加scriptManager.RegisterPostBackControl(this.btn_Upload);,但他没有找到按钮。

我该如何解决这个问题?谢谢

回答

1

一个可能的解决方案是将gridview(作为一个整体)注册为回发控件。 ScriptManager.RegisterPostBackControl(this.gvr);

+0

作品,谢谢! –

相关问题