C#下载主页内更新面板的按钮
问题描述:
我有一个主页,其中主页使用更新面板的网页表单。C#下载主页内更新面板的按钮
的问题是,每当我尝试下载一个文件,我得到这个错误:
无法因为代码优化或本机框上调用堆栈的顶部,以评估表达
这是代码
Response.ClearContent();
Response.ClearHeaders();
Response.AppendHeader("Content-Disposition",
string.Format("filename=Relatorio.{0}", "xlsx"));
Response.ContentType = "application/vnd.ms-excel";
Response.BinaryWrite(File_Converted_toBytes);
Response.Flush();
Response.End();
如果我创建例如一个新的项目,一个web形式之一,而只需创建一个空白页,有一个按钮里面的这个代码,一切正常。
有人有任何想法吗?
答
启动下载的按钮必须触发完整的回发。
<asp:UpdatePanel runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="YourControlID" />
</Triggers>
<ContentTemplate>
.....
</ContentTemplate>
答
你尝试到达“我的页面”像这样的你里面更新面板:作为一个UpdatePanel内,直到你做这样的事情是不可能的?
UpdatePanel up = (UpdatePanel)Master.FindControl("updadepanelID");
答
该解决方案由Cooleshwar
ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(
this.YourControlID)
好的评论,但我的网页内更新面板不可达。 因为我有 母版页有一个UpdatePanel 后来我的我的页面 – joab
你可能想试试这个专页上的负荷 - 'ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(this.YourControlID);' – Cooleshwar
嘿那条线它工作。 – joab