2012-08-28 46 views
0

我試圖使用UpdatePanel & Updateprogress顯示等待消息而PDF創建並刷新。見代碼updatepanel和updateprogress刷新PDF響應

<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"> 
    <ProgressTemplate> 
    Loading....... 
    </ProgressTemplate> 
</asp:UpdateProgress> 

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <Triggers> 
    <asp:AsyncPostBackTrigger ControlID="BT_Create" /> 
    </Triggers> 
    <ContentTemplate> 
    <asp:LinkButton ID="BT_Create" runat="server" OnClick="BT_Create_Click">Download</asp:LinkButton> 
    </ContentTemplate> 
</asp:UpdatePanel> 

protected void BT_Create_Click(object sender, EventArgs e) 
{ 
    byte[] downloadBytes = pdfConverter.GetPdfBytesFromHtmlString(htmlCodeToConvert, baseUrl); 
    System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; 
    response.Clear(); 
    response.AddHeader("Content-Type", "binary/octet-stream"); 
    response.AddHeader("Content-Disposition", "attachment; filename="test.pdf; size=" + downloadBytes.Length.ToString()); 
    response.Flush(); 
    response.BinaryWrite(downloadBytes); 
    response.Flush(); 
    response.End(); 
} 

問題是我能出現在等待消息,但沒有PDF是回報:S。在這個問題上的任何幫助?

乾杯。

+0

看起來像您正在將文件作爲內容發送到更新面板。這不會奏效。 – Magnus

+0

這對於Javascript來說非常簡單,它是一個顯示和隱藏兩個div的問題,而且您不必使用更新面板和scriptmanager。 –

回答

0

這是因爲您正在嘗試將Response.BinaryWrite更新到更新面板,這是無法完成的。您只能將html發送回更新面板。

請查看此link,它解釋了問題並提供了一個簡單的解決方案。