How to return value from html popup

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

User clicks an element in webform A; Web Form B pops up; User embeds with webform B; When closing web form B, perhaps using the submit button, the source element in webform a is updated with the value from web form B

Thanks.

+4
source share
3 answers

With ASP.NET MVC, I will probably make a DIV on the page initially hidden, possibly through AJAX, if the content depends on the values ​​selected on the start page. I would use the jQuery dialog box plugin to display this dialog box. The dialog may contain a form that is sent back to the server. You can also use the onclose handler for the dialog to copy the values ​​from the inputs in the dialog for use in the rest of the page. If you filled out the dialog via AJAX, you could force the server to generate HTML β€” say, by rejecting a partial view and returning it β€” or return json and create the dialog on the fly in the browser.

+6
source

I used cookies. I found this to be the only reliable way to do this. I use GrayBox for my dialog, so I have a function in the dialog box that looks like this:

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

Then, on my calling page, I launch a dialog box that displays partial in a 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); }); }); }); 

You will also need to grab a function from the Internet for SetCookie and GetCookie

Hope that helps

+3
source

You can use javascript from the popup to call functions on the opener using window.opener. That way, you can call the 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 you only need form data from a pop-up web form submitted to an open web form, then there is no need to make a server call.

+2
source

All Articles