简体   繁体   中英

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.

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM