Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return value from html popup

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.

like image 627
Pita.O Avatar asked Dec 17 '22 09:12

Pita.O


2 Answers

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.

like image 132
tvanfosson Avatar answered Dec 27 '22 08:12

tvanfosson


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

like image 35
Trevor de Koekkoek Avatar answered Dec 27 '22 07:12

Trevor de Koekkoek