2

I am calling a modal dialog. The dialog should perform an action in the code behind, then immediately close and show a notification in the parent window. I am using the following bit of code:

SP.UI.ModalDialog.showModalDialog({
    url:'{SiteUrl}/_layouts/myproject/UserActions/myaction.aspx',
    dialogReturnValueCallback:function(status,result){
       SP.UI.Notify.addNotification(result, false);
    }
});

The closing of the page is done by calling the following function at the end of the Page_Load:

private void Close(int status, string message)
{            
    Page.Response.Write(string.Format("<script type=\"text/javascript\">window.parent.SP.UI.ModalDialog.commonModalDialogClose({0}, '{1}');</script>",status,message));            
    Page.Response.Flush();
    Page.Response.End();
}

This works fine on my own machine, but on some other environments, this does nothing. The modal dialog remains open. If I check the contents of the frame I see that the bit of javascript is present in the head of the page. So it seems my .aspx page is fine, but the javascript is missing something?

  • Have you tried to profile it in IE9? F12 > Profile, this might throw you some insights. Failing this Chromes profiler is a little more powerful. From the face of it I think you have approached it correctly. You might also want to check the browser engine used, SharePoint attempts to use the IE8 rendering engine, which just doesn't like executing some JavaScript. – Hugh Wood Dec 18 '12 at 9:33
2

Mate, check out this post

You'll probably find out a possible solution.

  • 1
    Thanks! I didn't have need for the separate class, but by doing "Page.Response.Clear();" and using window.frameElement.commonModalDialogClose (as per that example) my issue is resolved. – Kenneth Van Coppenolle Dec 18 '12 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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