Simon Rigby
Simon Rigby

Reputation: 1786

Callback from jQuery UI Dialog

Absolutely convinced this must be a duplicate but I'll be damned if I can find it.

I have Page A which opens a jQuery UI dialog which loads Page B as its content. All I want to do is be able to pass back a value from Page B (the Dialog) to Page A when it closes (or more specifically when the use clicks Ok).

I'm imagining setting the value in a hidden field in Page B and then passing that back when the user clicks OK.

Thanks in advance.

Added Detail --- This is the JS that calls the dialog. The dialog opens, that part all works fine. The dialog does what I need it to do, I just need to pass the result of some interaction in that dialog to the calling page.

$(function () {

    $('#browseDialog').dialog({
        title: "Browse Images",
        autoOpen: false,
        width: 800,
        height:600,
        resizable: false,
        modal: true,
        buttons: {
            Ok: function () {
                $(this).dialog("close");
            }
        },
        close: function (event, ui) {
            $('body').removeClass('stopScrolling');
        }
    });

    $('#browseImages').click(function () {
        $('#browseDialog').load('@Url.Action("Browse", "Image")', function () {
            $('#browseDialog').dialog('open');
            $('body').addClass('stopScrolling');
        });
        return false;
    });

});

Upvotes: 0

Views: 94

Answers (1)

Mitya
Mitya

Reputation: 34556

If you're loading page B via load() then there's only really one page; they are merged into one and the same DOM.

Thus, the concept of passing data becomes redundant. That concept applies only if a second page is loaded into a frame - that would involve two, separate DOMs.

Just query the part of the DOM that the inserted content constitutes.

Upvotes: 1

Related Questions