3

I am using a Farm application page to display a search/edit modal dialog box. There is an asp button control on that page that I would like to use to close the dialog box. In my research on how to do this I found a suggestion to do this:

window.frameElement.commitPopup();

Is there a way to do the same thing but from the C# code behind the .aspx page instead in a button click handler? I'm not great with javascript so I'm trying to stick to what I know for now.

This is using SharePoint 2010 if that matters.

2

If you're using the SharePoint modal dialogs, you can close the modal in a click handler by registering javascript to run after the post back:

protected void btnSave_Click(object sender, EventArgs e)
{
    // DO STUFF;
    // ...

    Page.ClientScript.RegisterStartupScript(Page.GetType(), "saveSuccess",
        @"<script type='text/javascript'>
            ExecuteOrDelayUntilScriptLoaded(
                function() {
                    var args = {
                        arg1: '" + tbArg1.Text + @"',
                        arg2: '" + tbArg2.Text + @"'
                    };
                    SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK, args);
                }, 'SP.UI.Dialog.js');
        </script>");
}
| improve this answer | |

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.