2017-09-06 61 views
0

我有一個主頁,其中主頁使用更新面板的網頁表單。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形式之一,而只需創建一個空白頁,有一個按鈕裏面的這個代碼,一切正常。

有人有任何想法嗎?

回答

1

啓動下載的按鈕必須觸發完整的回發。

<asp:UpdatePanel runat="server"> 
    <Triggers> 
     <asp:PostBackTrigger ControlID="YourControlID" /> 
    </Triggers> 
    <ContentTemplate> 
     ..... 
    </ContentTemplate> 
+0

好的評論,但我的網頁內更新面板不可達。 因爲我有 母版頁有一個UpdatePanel 後來我的我的頁面 – joab

+0

你可能想試試這個專頁上的負荷 - 'ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(this.YourControlID);' – Cooleshwar

+0

嘿那條線它工作。 – joab

0

你嘗試到達「我的頁面」像這樣的你裏面更新面板:作爲一個UpdatePanel內,直到你做這樣的事情是不可能的?

UpdatePanel up = (UpdatePanel)Master.FindControl("updadepanelID"); 
0

該解決方案由Cooleshwar

ScriptManager.GetCurrent(this.Page).RegisterPostBackControl(‌​ 
this.YourControlID) 
相關問題