Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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>

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

4 Answers 4

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: http://www.chakkaradeep.com/post/Using-the-SharePoint-2010-Modal-Dialog.aspx help in any way?

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

There is another post with an example: http://blogs.msdn.com/b/chaks/archive/2011/09/14/modal-dialog-box-in-sharepoint-sandbox.aspx

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>
<td class="ms-separator"> </td>
<td class="ms-toolbar" nowrap="nowrap" align="right">
    <SharePoint:GoBackButton runat="server" ControlMode="Edit" id="gobackbutton2"/>
</td>

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

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

 
discard

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.