0

I have become onto a problem, where my Modual dialog window won't load it's UI before the code behind executes. But once the code behind executes, then the UI won't load until code has executed and basically there is no need to hold that dialog open anymore.

I call that modal dialog with Ribbon Button.

What I have tried:

I have tried to call code behind function with JS (Ajax) and all I get is not found in console log.

function callCode() {
        $.ajax({
            type: "POST",
            url: 'MyPage.aspx/MethodName',
            data: "",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (msg) {
                console.log(msg);
            },
            error: function (e) {
                console.log(e);
            }
        });
    }

Other thing, that I tried, was to make a hidden button and to click it, but since it takes so long to load UI, JS won't find that button and returns null.

I have tried to set timer in code itself, that I would wait for a certain time, before executing rest of the code, but still, UI keeps plank.

I managed to execute like I (almost) needed by clicking the button myself, but once I clicked it, then the execution started and UI didn't add items (even JS), that I would like to display for the user.

I really hope, that my problem is understandable and appreciate any kind of help! :)

1
  • Is it just a wait screen like SP.UI.ModalDialog.showWaitScreenWithNoClose? if I understand correctly you are wanting to show a modal while you perform some function. You could show the dialog, then perform the function asynchronously then on success callback close the modal.
    – MickB
    Commented Sep 9, 2015 at 16:02

1 Answer 1

3

Here's an example of loading a modal and then closing it after some work has finished.

$(document).ready(function(){
    ExecuteOrDelayUntilScriptLoaded(waitModal, "SP.js");    
})
function waitModal(){
    var waitModal = SP.UI.ModalDialog.showWaitScreenWithNoClose("Working on it...", "");    

    $.when(doWork()).done(function(){
        waitModal.close();
    });     
}
function doWork(){
    var dfd = $.Deferred()
    setTimeout(function(){
        //alert('hello');
        dfd.resolve();
    },1000);
    return dfd.promise();
}
1
  • Nice, this logic worked like a charm, big thanks to you! :)
    – Taurib
    Commented Sep 11, 2015 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.