Sharepoint2013 Modal Dialog won't load
Hi I have a simple page loaded into a SharePoint page library and trying to simulate a long run time without a full wait dialog. Below is the script that I have
<script type="text/javascript">
var waitDialog = null;
function DoWork() {
toggleProcessingStatus(true);
UpdateUI();
toggleProcessingStatus(false);
}
function UpdateUI()
{
var lblControl = document.getElementById("lbl");
for (i = 0; i < 20000; i++)
{
lblControl.innerText = lblControl.innerText + i;
}
}
function toggleProcessingStatus(showStatus) {
if (showStatus) {
ExecuteOrDelayUntilScriptLoaded(ShowWaitDialog, "sp.js");
}
else {
if (waitDialog != null) {
//setTimeout(CloseWaitDialog, 5000);
CloseWaitDialog();
}
}
}
function ShowWaitDialog() {
waitDialog = SP.UI.ModalDialog.showWaitScreenWithNoClose('Updating...', 'Please wait while update completes...', 150, 330);
}
function CloseWaitDialog() {
if (waitDialog != null) {
waitDialog.close();
}
}
</script>
<input type="button" id="btnShowDialog" title="Do Long Running Work" name="Do Long Running Work" onclick="javascript: DoWork();" value="Do Long Running Work"/>
Label: <label id="lbl" title="Test">Test Wait Screen</label>
Any help is greatly appreciated.
Thank you, Mallikarjun
+3
source to share
3 answers
As with the other mentioned answers, you have to make sure the script sp.ui.dialog.js script is loaded. You can do it with code like below
SP.SOD.executeOrDelayUntilScriptLoaded(function () {
SP.UI.ModalDialog.showModalDialog(options);
}, "sp.ui.dialog.js");
//ensure script is loaded
SP.SOD.executeFunc("sp.ui.dialog.js", null, null);
Inclusion in the template as executeOrDelayUntilScriptLoaded
well as executeFunc
provides the following:
- executeOrDelayUntilScriptLoaded - before sp.ui.dialog is loaded before executing enclosed code
- executeFunc - make sure sp.ui.dialog is loaded if not already requested on the page
0
source to share