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.
<a id="popAspxWeb" href="#" onclick="javascript:PopPage('ModalPopup.aspx','galbal_variable_data');">Click to Popup</a>
here's the javascript code to open popup window.
<script type="text/javascript">
function PopPage(page, data) {
var result = window.showModalDialog(
page, // popup this page
data, // with this data
"dialogWidth:500px; dialogHeight:500px; resizable:no; status:no; center:yes");
}
</script>
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.
<input id="hidData" runat="server" type="hidden" />
<input id="postback" runat="server" type="hidden" value="false" />
here's the javascript:
<script type="text/javascript">
var data = ""; // global variable to store data from parent window.
$(document).ready(function() { //jQuery code to be executed when document is fully loaded.
args = window.dialogArguments; // obtain argument data and assign to global variable.
if ($("#postback").val().toString() == "false") { // if first visit to page
$("#hidData").val(data); // assign argument data from global variable to hidden field.
$("#postback").val("true"); // flag the form is posted back.
document.forms[0].submit(); // trigger form post.
}
});
function ReturnAndClose() { // you can optionally return data back to the parent window.
window.close(); // this closes modal pop up.
window.returnValue = document.getElementById('return_data').value; // this returns a value to parent window.
}
</script>
Step 3 code:
code behine to access galbol variable data.
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack)
{
string data = this.hidData.Value;
this.Session["data"] = data;
}
}