I am using some JavaScript (Client OM) code to open a dialog. Here's a snippet:
function OpenModalForm() {
//snip
var opt = {
url: url,
width: 800,
height: 600,
title: title || "",
dialogReturnValueCallback: OnDialogClose
};
SP.UI.ModalDialog.showModalDialog(opt);
}
function OnDialogClose(dialogResult, returnValue) {
alert("dialog result: " + dialogResult );
if ( dialogResult == SP.UI.DialogResult.OK ) {
SP.UI.ModalDialog.commonModalDialogClose(SP.UI.DialogResult.OK);
}
if ( dialogResult == SP.UI.DialogResult.cancel ) {
SP.UI.ModalDialog.commonModalDialogClose(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="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" xmlns:x="http://www.w3.org/2001/XMLSchema">
<TBODY>
<TR>
<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>
</TR>
</TBODY>