how to effectively use SP.UI.ModalDialog.OpenPopUpPage(url, callback, width, height)

Answered how to effectively use SP.UI.ModalDialog.OpenPopUpPage(url, callback, width, height)

  • Monday, June 13, 2011 6:37 AM
     
     

    on my webpart i wan to use this so that onclick of links opens in new modal popup and after the popup is closed, then the parent page must refresh..

    SP.UI.ModalDialog.OpenPopUpPage(url, callback, width, height)

    so i want to know how to write callback suppose i am using this in code behind file as:

    btnedit.attributes.add("onclick","javascript:OpenPopUpPage('http://test.com')");

All Replies

  • Monday, June 13, 2011 8:24 AM
     
     Answered Has Code

    You can add a method like this to your JavaScript:

     

     

    function MyDialogCallback(dialogResult, returnValue)
    {
     // Do stuff here
    }
    
    SP.UI.ModalDialog.OpenPopUpPage('http://test.com', MyDialogCallback)
    

    Hope this helps
    Phill

     


    helpful? …please mark it so!

    Lightning Tools Check out our SharePoint Tools and Web Parts
    BCS Meta Man Automatic BCS Model Generation
    BCS Tester Man Open Source BCS test client
    Twitter LinkedIn
    • Marked As Answer by ogsim07 Monday, June 13, 2011 9:39 AM
    •  
  • Monday, June 13, 2011 9:40 AM
     
      Has Code

    You can add a method like this to your JavaScript:

     

     

    function MyDialogCallback(dialogResult, returnValue)
    {
     // Do stuff here
    }
    
    SP.UI.ModalDialog.OpenPopUpPage('http://test.com', MyDialogCallback)
    

    Hope this helps
    Phill

     


    helpful? …please mark it so!

    Lightning Tools Check out our SharePoint Tools and Web Parts
    BCS Meta Man Automatic BCS Model Generation
    BCS Tester Man Open Source BCS test client
    Twitter LinkedIn
    ok..k..thakns
  • Thursday, June 14, 2012 8:12 PM
     
     

    This will reload the parent when you close the form either by clicking 'Close/Cancel' button from your custom form/modal window OR when you click on 'X' from top right of modal window. But how to reload the parent only when form is submitted using 'Submit' button click.

    -Ajay

  • Tuesday, June 19, 2012 10:57 PM
     
     Proposed

    I got this working.... 

    In Parent window use below methods to open modal window

    function launchModal(url, height, width) {
        var options = SP.UI.$create_DialogOptions();
        options.url = url;
        options.width = width;
        options.height = height;
        options.dialogReturnValueCallback = Function.createDelegate(null, CloseCallback);
        SP.UI.ModalDialog.showModalDialog(options);
    }

    function CloseCallback(result, target) {
        if (result != SP.UI.DialogResult.cancel) {
            window.parent.location = window.location.href;
        }
    }

    function CloseFormAndReloadParent() {

        window.frameElement.commitPopup();
    }

    In child/modal window use below method to submit your changes when you are done with processing like on server side button click:

    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "msg", "javascript:CloseFormAndReloadParent();", true);

    Hope this helps

    -Ajay


    - Ajay