0

Is it possible to have results from another page returned to a JavaScript method or a C# controller action?

I have a shared complex page that's used all over my website that's currently used to set a single variable on the user data in the C# back end. When the user has finished the shared complex page, I return to the referring page. The page that I've returned to contains the newly selected variable when the user returns as it's refreshed or alternatively passed as a url parameter to the returning page.

I have a new page where I'd like the variable from my shared complex page to be returned. However there will be multiple instances of this variable on the page and they're actually different data to the previously stored single variable on the user data in the C# back end. i.e. I'd like to have several buttons on the page that lead to my shared complex page and when the user returns the data for each button will be displayed next to the button.

Is there a way in JavaScript or C# to display another page and have the result returned to the method that instantiated the display of the page? If my back end was implemented in scheme I'd use a continuation to achieve this result. Is there any equivalent in C#? I've been looking at async tasks in C# but none of the examples show a user interacting with another page as part of the asynchronous operation. Is this possible?

If not I'll have to pass the value back to the new page via URL parameters. I would like to avoid this because of the amount of contextual data I'd need to pass between the two pages. I'd thought of using a redirect from the shared complex page to update the new data on the back end before returning to the new page to solve half the problem but this site works on mobile so the network latencies rule out redirects. Also having the complex shared page as a pop up dialog within the new page won't really work as it's a) complex b) the new page can be used a pop up on an existing page and having a pop up from a pop up is unsupported on Bootstrap.

Giles Roberts
  • 6,407
  • 6
  • 48
  • 63
  • 1
    Hey, your description is confusing. Can you clear this up a bit? It sounds like you're trying to share data between two different pages on two different browsers? Or, are you doing traditional postbacks to the server and trying to get the data from one page into the other? It's not entirely clear what you're doing here. – Thinking Sites Jul 04 '14 at 18:23
  • @ThinkingSites No I'm trying to share information between pages in the same browser. What I'm effectively trying to do is use my shared complex page as a dialog. I'm trying to be lazy and avoid passing any location context to the shared complex page. The shared complex page currently uses this location context to determine which page it should return to. The returning page is passed the return value of the complex page as a parameter when it's called. Again what I'm trying to do is be lazy and avoid having to pass the context data as per http://double.co.nz/scheme/modal-web-server.html. – Giles Roberts Jul 07 '14 at 09:38
  • @ThinkingSites I'm an old Windows programmer and what I'm trying to emulate is calling a shared dialog from any point in the program without having to put code into the dialog that's worrying about where it should be returning to. – Giles Roberts Jul 07 '14 at 09:40
  • You don't really have shared resources like that between windows in the same browser except maybe cookies. There are things like indexed DB which is a shared datasource per domain, but that may not be what you're looking for, since that's not really messaging. There are a variety of HTML5 data storage options right now. What you're probably really looking for is an ajax solution where you go back to the server for the data you need, rather than trying to share data between browser windows. What's your server-side language, that might help in figuring out your solution. – Thinking Sites Jul 07 '14 at 13:13
  • @ThinkingSites My server side language is C#. And that's my exact problem. I don't have continuations available in this language. I was wondering if the new async features of .NET 4.5 could be adapted to fulfil this role. Again see http://double.co.nz/scheme/modal-web-server.html for exactly what I'm after. Using indexed DB would still require me to write code to store the context of the request so I could retrieve the result so that doesn't save me any work. Thanks for the idea though. I am able to implement all of this using a combination of back end code and or Ajax. – Giles Roberts Jul 07 '14 at 14:44
  • Yeah, you're going to have to store the state seperately, most likely in a session variable while you compile what you need, then when you're done, fire off an ajax to complete your workload. – Thinking Sites Jul 07 '14 at 14:51

1 Answers1

1

The sharing of data between web pages, without an established continuation medium, requires the use of a shared state somewhere, like session variables or cookies. As each page changes the state, it can go back to the server, update that session, and when the process is done, you'd read that session via ajax and complete your process.

Thinking Sites
  • 3,494
  • 17
  • 30