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 have a custom page that I load in a SharePoint dialog. I call the javascript from an ASPX page, but when I close the dialog I want the javascript callback to "push" a value back to my ASPX page. Is this possible?

share|improve this question

Yes, certainly it's possible and can be done through dialogReturnValueCallback parameter.

Sample code for popping up the dialog:

var options =
        url: '/_layouts/CustomDialogPage.aspx',
        title: 'My modal dialog',
            function (dialogResult, returnValue) {
                if (dialogResult == SP.UI.DialogResult.OK) {

... and for returning the value (from CustomDialogPage.aspx):

window.frameElement.commitPopup('Hello from custom dialog page!');

If you're using postbacks and server-side code in your custom dialog page, you should use the following code to achieve this:

Response.Write("<script type='text/javascript'>window.frameElement.commitPopup('Hello from custom dialog page!');</script>");
share|improve this answer
it's the other way around: when I close my dialog, I want to sent back a value to the javascript caller(Dialog->callback->aspx) who call the showModalDialog. – Gabriel Mongeon Nov 2 '11 at 20:37
So you want execution to continue after the call to showModalDialog, and use the returned value, right? Just move your code into the callback. Javascript can't wait synchronously, it is completely asynchronous by design. – Andrey Markeev Nov 2 '11 at 20:46
up vote -2 down vote accepted

Here's what I've done:

function dialogCallback(result, value) {
    if (result === SP.UI.DialogResult.OK) {
        // find the control to set the value
        var obj = document.getElementById(getRealId('MY_REALLY_UNIQUE_ID'));

        if (obj != null) {
            obj.value = value;
// Get the complete id of the control
function getRealId(partialid) {
    var re = new RegExp(partialid, 'g');
    var elems = document.getElementsByTagName('*'), i = 0, el;
    while (el = elems[i++]) {
        if ( {

It's was more an javascript thing than a Sharepoint one.

share|improve this answer

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.