Tuesday, March 31, 2015

Processing message for long code operations in SharePoint

As a SharePoint Developer you may need to show spinning wheel or Processing sign while lengthy code operations. You have probably seen this while creating new web application or site collection in Central Administration. You may need to show the processing messages for server side or client side long operation code. Showing processing message improves the user experience. SharePoint provides some nice ways to show processing message while long running code operations.

Server side code


On Server side, if you are executing some code that takes longer to process then you can use SPLongOperation Class to show processing request message. SPLongOperation would require redirecting the user to the destination page. Destination page could be same page or confirmation page. Following is the sample code to get the processing message for server side code:

Once long code is executed, you can end the operation by calling End() method. If you are calling SPLongOperation in modal popup then call EndScript() method to close the current dialog box. For example:


Client side code


For client side long operations, SharePoint provides following options to show wait screen dialog:

SP.UI.ModalDialog.showWaitScreenSize(title, message, callbackFunc, height, width) Method

Displays a wait/loading modal dialog with the specified title, message, height and width. Height and width are defined in pixels. Cancel button is shown. If user clicks it, the callbackFunc is called.

SP.UI.ModalDialog.showWaitScreenWithNoClose(title, message, height, width) Method

Displays a wait/loading modal dialog with the specified title, message, height and width. Height and width are defined in pixels. Cancel/close button is not shown.
Following is the code example to show the wait dialog on client side:

No comments:

Post a Comment