I have a client global variable in javascript. I need to access this global variable from the server side which is living on different page. how can i achieve this without a query string? if session state required, then how can i set the session from the javascript?
EDITED
ok.. here is the full scenario.. the page itself is a sharepoint web page, i have only control on the web part. within the webpart i have a button that does window.open to open another page. Now how can i pass the javascript variable from the main page to the other page and make it accessible in the code-behind?
I can think of a few ways to do it, but I’ll recommand you this. The basic steps are:
Use JavaScript to popup a modal dialog alone with the global variable you want to pass as a argument (not query string).
On the popup page, use JavaScript to set the global variable to a hidden field and then initiate a postback to itself.
At code behind, retrieve the global variable from hidden field and store it in session data.
Now, the global variable is available in Session space.
Note: You’ll need jQuery 1.7.1 or higher.
Step 1 code:
this is your popup link or button.
here’s the javascript code to open popup window.
Step 2 code:
you’ll need these. first one to store the data get passed in and second one to flag page postback or not.
here’s the javascript:
Step 3 code:
code behine to access galbol variable data.