views:

2686

answers:

4

Hi, I need a terse, clean way to implement this in asp.net mvc (+/- jquery or js)?

User clicks an element in webform A; Webform B pops up; User interracts with webform B; On closing webform B, probably by a submit button, the source element in webform a is updated with a value from webform B

Thanks.

+5  A: 

With ASP.NET MVC, I'd probably render a DIV on the page, initially hidden, perhaps via AJAX if the contents depend on values selected on the initial page. I'd use the jQuery UI dialog plugin to popup the dialog. The dialog could contain a form that submits back to the server. You could also use the onclose handler for the dialog to both copy values from the inputs in the dialog for use on the rest of the page. If you populated the dialog via AJAX you could have the server generate the HTML -- say by rendering a partial view and returning it -- or return json and generate the dialog on the fly in the browser.

tvanfosson
+3  A: 

I've resorted to using cookies. I've found this to be the only reliable way to do this. I'm using GrayBox for my dialog, so I have a function in the dialog that looks like this:

    function selectValue(id, name) {
      SetCookie("_someuniqueprefix_RetID", id);
      SetCookie("_someuniqueprefix_RetValue", name);
      parent.parent.GB_CURRENT.hide();
    }

Then in my calling page I am launching the dialog which displays a partial in the GrayBox:

$(function() {
    var selectUrl = '/_somecontroller/Select';
    // attach a method to the chooseButton to go and get a list of
    // contact persons to select from
    $("#chooseButton").click(function() {
        GB_showCenter('Select My thing', selectUrl, 500, 620, function() {
            var id = GetCookie("_someuniqueprefix_RetID");
            var value = GetCookie("_someuniqueprefix_RetValue");
            DeleteCookie("_someuniqueprefix_RetID", "/", "");
            DeleteCookie("_someuniqueprefix_RetValue", "/", "");
            $("#MyID").val(id);
            $("#MyName").val(value);
        });
    });

});

Also you'll need to grab a function off the web for SetCookie and GetCookie

Hope that helps

Trevor de Koekkoek
+1  A: 

jQuery is my cup of tea! Since your example already uses jQuery, I'll continue.

I would take a serious look at jQuery UI (Dialog), as it seems you are describing some kind of parent (a) child (b) relationship. I'm writing something like that at work, so here goes:

http://waynekhan.com/sandbox/index.php/demo/dialog

[Edit]

It's a bit heavy at ~500kb as I've used the uncompressed versions of jQuery and jQuery UI.

Wayne Khan
+2  A: 

You can use javascript from the popup window to call functions on the opener via window.opener. So your popup could call a function on the parent page to pass the data back when the user clicks the submit button.

I'm not sure what your requirements are, but IMO using ajax for this sounds like overkill. If all you need is some form data from the popup webform passed to the opener webform, then there's no need to make a call to the server.

Kevin Tighe