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.
I have attempted to you your code above to close the SP.UI.ModalDialog.showWaitScreenWithNoClose which I am calling from an Application page button in SP 2010, but I get “Object expected” error on the page. Where exactly are you putting the JQuery Code? I have attempted to fire with a response.write
“Context.Response.Write(“” + getjQueryCode(“$(\”.ms-dlgContent img\”).last().closest(‘.ms-dlgContent’).css(‘display’, ‘none’); $(‘.ms-dlgOverlay’).css(‘display’, ‘none’);”) + “”);)”
and a RegisterClientScriptBlock from the code behind both had same result.
private string getjQueryCode(string jsCodetoRun)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(“$(document).ready(function() {“);
sb.AppendLine(jsCodetoRun);
sb.AppendLine(” });”);
return sb.ToString();
}
Am I missing something?
Hi John,
I had some issues in the code I originally posted, I was midway through implementation when I posted this.
I had to change the code slightly, check out the updated post for the code – this works flawlessly for me now, let me know if this solves the problem.
To answer your question though – I am putting the JQuery code in a referenced .js file from my application page. It’s simply referenced in a in the of my application page.
You should be able to either use ScriptManager.RegisterStartupScript, OR add a script manager and do:
For example.
Thanks,
Matthew Cosier
Hazaa