2

I used OpenPopupPage to display an application page as a modal dialog box to collect some user input. I would like to take the results of that user input and populate two text boxes on the main page (an .ascx control). How do I pass that data back down? Should I stick it in session and then just refresh the main page after they have made their selection in the modal dialog box?

Shane Wealti
  • 534
  • 3
  • 11
  • See: http://sharepoint.stackexchange.com/questions/90938/sp-ui-modaldialog-commonmodaldialogclose-doesnt-close/90943#90943 if you want to pass the data back from server side. – RJ Cuthbertson Feb 25 '14 at 22:51

1 Answers1

2

You can pass the data in the arguments of the SP.UI.ModalDialog.commonModalDialogClose function and handle them in the callback function of the dialog.

In the parent page:

<script type="text/javascript">
    function showModal() {
        var options = {
            url: '/web/_layouts/Dialog/TestModal.aspx',
            title: 'Hello World',
            allowMaximize: false,
            dialogReturnValueCallback: modalClosed,
            args: {
                arg1: $('#<%= tbArg1.ClientID %>').val(),
                arg2: $('#<%= tbArg2.ClientID %>').val()
            }
        };
        SP.UI.ModalDialog.showModalDialog(options);
    }
    function modalClosesd(result, args) {
        if (result == SP.UI.DialogResult.OK) {
            $('#<%= tbArg1.ClientID %>').val(args.arg1);
            $('#<%= tbArg2.ClientID %>').val(args.arg2);
        }
    }
</script>

In the modal:

<script type='text/javascript'>
    function okClicked() {
        var args = {
            arg1: $('#<%= tbArg1.ClientID %>').val(),
            arg2: $('#<%= tbArg2.ClientID %>').val()
        };
        SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, args);
    }
</script>
RJ Cuthbertson
  • 8,342
  • 6
  • 38
  • 76