2012-03-01 28 views
0

這裏的簡化方案:ASP.Net:UpdatePanel的回發文件附件問題

我有兩個部分的頁面:搜索部分,包含列表的結果網格。用戶在結果網格中檢查每一行的複選框,並將其添加到一個zip文件中,然後單擊一個按鈕,該按鈕發回到另一個生成zip文件的頁面。

因此,我們有:

[UpdatePanel1] 
...Search Inputs... 
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" /> 
[/UpdatePanel1] 
[UpdatePanel2] 
..Results Grid.. 
<asp:Button ID="btnZip" runat="server" Text="Zip" PostBackUrl="~/Zip.aspx"/> 
[/UpdatePanel2] 

凡Zip.aspx的邏輯是這樣的:

SearchPage previousPage = (SearchPage)PreviousPage; 
List<Files> docs = previousPage.GetSelectedFiles(); 

...do logic... 

Response.ContentType = "application/zip"; 
Response.AddHeader("Content-Length", zipBytes.Length.ToString()); 
Response.AddHeader("Content-Disposition", "attachment; filename=Test.zip"); 
Response.BinaryWrite(zipBytes); 
Response.End(); 

頁正常工作中,你可以搜索,它正確地填充結果網格中,並且您可以選擇任意行並按需要多次點擊「Zip」按鈕,並且每次都能正常工作。

不過,如果你已經打了「壓縮」按鈕至少一次,並返回到搜索條件,然後點擊「搜索」再次,它會導致這個JavaScript錯誤:

Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled. 
Details: Error parsing near 'PK'. 

看着提琴手,它似乎像搜索按鈕回發到「Zip.aspx」而不是自己。有沒有辦法解決這個問題?

回答

1

Looking at fiddler, it seems like the Search button is posting back to "Zip.aspx" instead of itself. Is there a way I can work around this?

如果是這樣的情況下,嘗試添加的OnClientClick處理程序搜索按鈕,並確保表單操作設置爲搜索頁面本身,而不是Zip.aspx

喜歡的東西:

function CheckPostBackURL() 
{ 
    document.getElementById('aspNetForm').action="Search.aspx"; 
} 

我不知道它是否會工作,但這是一個想法。

+0

是的,下面一行工作:btnSearch.Attributes [「onclick」] =「document.forms [0] .action ='Search.aspx';」 + ClientScript.GetPostBackEventReference(btnSearch,null); – John 2012-03-01 17:43:33