There’s one nice feature of the SharePoint 2010 UI framework which lets you display a wait dialog with no close button:
SP.UI.ModalDialog.showWaitScreenWithNoClose('Please wait ...', 'Please wait while we process your request ...', 80, 400);
You may want to run this on client click of a button, which ultimately posts back the page. In my case it was a dialog which did some processing, then ultimately closed.
If you call the above function, and the page posts back, when it returns the wait dialog will still be there… it won’t go away!
Okay, so you say – it should be as simple as calling window.frameworkElement.commitPopup(); … negative, this does NOT work for the above dialog (because likely when you’re executing this, you’re executing it on the main window, not the wait dialog’s frame, which renders this call useless.. and in most cases if you have other SPDialog’s open, it will close THEM, but not the wait dialog.
ANYHOW… JQuery to the rescue: Here’s the fix…
Simply hook a document.ready on the page which is posting back, and manually hide the Dialog and overlay, by doing the following:
$(document).ready(function () {
ExecuteOrDelayUntilScriptLoaded(function () {
// UPDATE: Original post I had this executing in the current frame, I change this now to execute on the top frame, otherwise it can't find the dialog
if (($(top.window.document).find('.ms-dlgContent')).length > 1) {
$(($(top.window.document).find('.ms-dlgOverlay'))).css('display', 'none');
$($(top.window.document).find('.ms-dlgContent')[1]).remove();
}}, "sp.js");
// Demand the loading of the SP.js script (demand ribbon, which cascades into sp.js and a few other required items such as sp.dialog.js)
SP.SOD.executeFunc('ribbon', null, function () {});
This will search for all spinner images within the currently open dialogs, and return the last element found (which is generally always the top level dialog – the wait dialog.). It then searches upward for the closest dialog frame, then hides it with a bit of CSS magic. You could probably search upward for the frame element and perhaps close it, but this suited what I needed to do perfectly, because the page will post back soon enough and it will be gone anyway.