0

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;
    });

});
5
  • How are you loading Page B into a dialog? Via an async request which then pipes the html into the dialog body via .html()? We need a little more information before we can be able to help. Commented May 7, 2015 at 21:57
  • using .load() in the calling page Commented May 7, 2015 at 21:59
  • 3
    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. Commented May 7, 2015 at 22:04
  • Ah of course .. so I should be able to access the hidden field in this case before closing the dialog? Commented May 7, 2015 at 22:05
  • Do you want to put this in an answer and I'll accept it or shall I answer it myself .. may be of value to someone else who has spent an hour not seeing the wood from the trees :p Commented May 7, 2015 at 22:11

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Excellent .. and my case is working as expected .. greatly appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.