[英]How do you call master page methods from a content page when the button is inside an update panel?
[英]C# Download button inside of Update Panel in Master Page
我有一個具有母版頁的 web 表單,該母版頁使用更新面板。
問題是,每當我嘗試下載文件時,都會出現此錯誤:
無法評估表達式,因為代碼已優化或本機框架位於調用堆棧頂部
這是代碼
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 forms 一個,然后創建一個空白頁面,其中有一個帶有此代碼的按鈕,一切正常。
有人知道嗎?
啟動下載的按鈕必須觸發完整的回發。 在UpdatePanel內部,直到您執行以下操作是不可能的:
<asp:UpdatePanel runat="server">
<Triggers>
<asp:PostBackTrigger ControlID="YourControlID" />
</Triggers>
<ContentTemplate>
.....
</ContentTemplate>
您是否試圖像這樣在“我的頁面”內訪問更新面板?
UpdatePanel up = (UpdatePanel)Master.FindControl("updadepanelID");
該解決方案由Cooleshwar評論
ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(
this.YourControlID)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.