2011-02-16 72 views
0

我正在使用SPLongOperation運行冗長的操作。完成後,齒輪頁面將重定向到啓動長操作的原始頁面。我無法使用SPLongOperation.Endscript向oriignal頁面寫入任何內容。下面是我使用顯示SPLongOperation的結果

using (SPLongOperation operation = new SPLongOperation(this.Page)) 
{ 
//....................... 
//....................... 
StringBuilder endScript = new StringBuilder(); 
endScript.Append("document.write('Success!!');"); 

operation.End(Request.Url.ToString(), SPRedirectFlags.UseSource, HttpContext.Current, String.Empty, endScript.ToString()); 
} 

回答

0

您將不能寫任何東西到調用頁面的代碼,一個新的HTTP請求已作出向您展示與紡車的頁面,而你的行動正在取得進展然後你被重定向回指定的URL(使用新的請求)。

顯示一個成功消息的最簡單的方法是用什麼代替你的String.Empty參數一樣

operation.End(Request.Url.ToString(), SPRedirectFlags.UseSource, HttpContext.Current, "success=1"); 

http://msdn.microsoft.com/en-us/library/ms450341.aspx

,然後加載事件到特定的查詢字符串傳遞給您的URL呼叫,檢查你是否有這個參數,並顯示相關的消息(最好將項目添加到HttpContext.Items或做一個帖子,而不是一個get刪除查詢字符串,但建議的實現將阻止你改變你的長期操作呼叫和行爲)

希望這會有所幫助。

+0

您好,感謝您的答覆。不幸的是,我的要求不僅僅是發佈簡單的失敗信息。長操作會創建一個小的XML文件,我必須使用該文件在調用長時間運行的頁面上進行渲染。我試圖用Endscript來完成這個任務。由於文件的大小,我不想通過將它保存在會話變量中來佔用服務器資源。 – ashwnacharya 2011-02-26 05:04:40

0

嘗試的警報 - 爲我工作..

Script.Append("alert('Success!!');"); 
0

這可能會有幫助:http://www.sharepoint-tips.com/2012/07/reporting-code-errors-when-running-code.html

SPLongOperation longOp = new SPLongOperation(this.Page); 
StringBuilder sbErrors = new StringBuilder(); 
longOp.Begin();try 
{ 
throw new Exception("Sample"); 
} 
catch(Exception ex) 
{ 
    sbErrors.Append("An error occurred: " + ex.MEssage); 
} 

if 
(sbErrors.Length > 0) 
{ 
longOp.EndScript("document.getElementById('s4-simple-card-content').innerHTML = \"Errors have occurred during the submission. Details: " + sbErrors.ToString() + " \";"); 
} 
//close the dialog if there were no errors 
longOp.EndScript("window.frameElement.commitPopup();");