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?

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>

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.