Maybe a chicken/egg problem.
Based on this answer: https://stackoverflow.com/a/27190520/1438215
I want to use javascript to populate the value of an asp.net hidden field (as soon as it's possible), and then access the value of that populated field in the server-side Page_Load event.
Sample:
aspx portion:
<div id="div_BrowserWindowName" style="visibility:hidden;">
<input type="hidden" name="ctl00$ctl00$BodyContent$MainContent$hf_BrowserWindowName" id="BodyContent_MainContent_hf_BrowserWindowName" />
</div>
<script type="text/javascript">
function PopBrowserWindowName() {
if (typeof window.name != undefined) {
if (window.name == '') {
var d = new Date();
window.name = '_myWnd_' + d.getUTCHours() + d.getUTCMinutes() + d.getUTCSeconds() + d.getUTCMilliseconds();
}
var eDiv = document.getElementById('div_BrowserWindowName');
var e = eDiv.getElementsByTagName('input')[0];
e.value = window.name;
alert(e.value);
}
}
window.onload = PopBrowserWindowName();
</script>
aspx.cs portion (page_load) event:
if (hf_BrowserWindowName != null)
{string winID = hf_BrowserWindowName.Value;}
This does works during postbacks, but does not work on the page's initial load.