Search This Blog

Sunday, November 27, 2011

Displaying Processing dialog with SPLongOperation in Sharepoint 2010

Whenever in your code you are executing some piece of code that takes longer to process, you can make use of SPLongOperation class (Microsoft.SharePoint.SPLongOperation) to show user in user interface that the system is processing the request. This can be easily accomplished by wrapping your  custom code inside the statement shown below:

using (SPLongOperation objLongOperations = new SPLongOperation(this.Page))


objLongOperations.LeadingHTML =
"Processing request";

objLongOperations.TrailingHTML = "Please wait while the request is being processed...";


//Write your code here

System.Threading.Thread.Sleep(25000);//added to show the processing screen. Nor required in actual implementation



If you are opening a popup window to show the processing, then instead of objLongOperations.End(), you can call the objLongOperations.EndScript() method to close the current dialog box as:


Also you can send some parameters to the parent window if you want to do some processing on the parent window (like doing a postback on the parent window) by writing the following script:

objLongOperations.EndScript("window.frameElement.commonModalDialogClose(1, 'Your custom value which can be used in parent page if required');");

No comments:

Post a Comment