SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using some JavaScript (Client OM) code to open a dialog. Here's a snippet:

    function OpenModalForm() {


    var opt = {
        url: url,
        width: 800,
        height: 600,
        title: title || "",
        dialogReturnValueCallback: OnDialogClose


    function OnDialogClose(dialogResult, returnValue) {
    alert("dialog result: " + dialogResult );

    if ( dialogResult == SP.UI.DialogResult.OK ) {
    if ( dialogResult == SP.UI.DialogResult.cancel ) {

This dialog opens a custom form. The problem is the callback is not fired when pressing save or cancel. The callback is fired if I click the upper-right hand X of the modal. How do I get the call back to fire when clicking the buttons on the custom form?

Note Everything works as expected on OOTB forms. I have hard coded the custom form buttons to run the commonModalDialogClose and that works. I'm trying to not do that. I'd like to take advantage of the callback, if at all possible.

Update This is the HTML rendered for the buttons:

<TABLE border=0 cellSpacing=0 cellPadding=4 width="100%" xmlns:ddwrt2="urn:frontpage:internal" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:__designer="" xmlns:asp="" xmlns:d="" xmlns:x="">
        <TD class=ms-vb noWrap><INPUT onclick="javascript: __doPostBack('ctl00$***SNIP***','__commit')" name=btnSave value=Save type=button jQuery16406037463754413849="2"></TD>
        <TD class=ms-vb width="99%" noWrap><INPUT onclick="javascript: __doPostBack('ctl00$***SNIP***','__cancel')" name=btnCancel value=Cancel type=button jQuery16406037463754413849="1"></TD>

share|improve this question
For clarity, it would be great if you could post the code of your form. At least the "buttons" part of the markup. – Andrey Markeev Oct 26 '11 at 19:21
up vote 1 down vote accepted

Tried using the same controls that OOTB modal dialog forms use? You'll probably need to, as those will trip javascript functions needed for the callback.

share|improve this answer
I have not tried to use those controls. I'll check to see if they are available within SharePoint Designer. Do you know if they are? – iOnline247 Oct 26 '11 at 18:46
You'll probably have to have a look into the LAYOUTS folder and see what application pages are loaded. Or perhaps even the ControlTemplates folder, as it'll probably be loaded via usercontrol. – James Love Oct 26 '11 at 18:47
I'll give it a go... Thanks for the insight as always. – iOnline247 Oct 26 '11 at 18:51

I was looking at the same challenge a couple of months back. Project ended up being cancelled but would the section of this post: help in any way?

this.Page.Response.Write("<script type=\"text/javascript\">window.frameElement.commonModalDialogClose(1, 1);</script>"); 

There is another post with an example:

share|improve this answer
Thanks Greg for the great link. I tried the code: Function.createDelegate, but I didn't have any success with it. Any tips on how to use the callback within SP.UI.ModalDialog.showModalDialog? – iOnline247 Oct 27 '11 at 12:53

After looking into it, there are two ways of creating a custom form. One via the ribbon and one from the Data Source Details pane. The first way produces controls with code similar to:

<td class="ms-toolbar" nowrap="nowrap">
    <SharePoint:SaveButton runat="server" ControlMode="Edit" id="savebutton2"/>
<td class="ms-separator"> </td>
<td class="ms-toolbar" nowrap="nowrap" align="right">
    <SharePoint:GoBackButton runat="server" ControlMode="Edit" id="gobackbutton2"/>

The second way of creating a custom form produces code similar to:

<td nowrap="nowrap" class="ms-vb">
    <input type="button" value="Save" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent('__commit')}" />
<td nowrap="nowrap" class="ms-vb" width="99%">
    <input type="button" value="Cancel" name="btnCancel" onclick="javascript: {ddwrt:GenFireServerEvent('__cancel')}" />

Using the latter, you lose control of firing the callback. So the fix is to change the code to use the SharePoint control and not rely on the ddwrt:GenFireServerEvent. This will fire the callback as intended.

share|improve this answer

How about something like this: onclick=”window.frameElement.commitPopup(); return false;”

share|improve this answer
I'd like to use the callback within the SP.UI.ModalDialog.showModalDialog if possible. I'm thinking it's not possible, but I don't know why it's that way. – iOnline247 Oct 27 '11 at 12:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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