I'm facing a challenge where I need to save a value during the Page_Unload event, store it in Session or ViewState, and then access it from javascript without needing to refresh the page. The issue I'm encountering is that the Session's value only updates after a postback or when the page is refreshed. How can I accomplish this without having to refresh the page?
Here is an example:
The .cs file
public void Page_Unload(object sender, System.EventArgs e)
{
string s = "some text";
if (s.Contains("foo"))
{
Session["bar"] = 37;
} else {
Session["bar"] = 38;
}
}
The .aspx file
<script type="text/javascript">
function tst() {
alert('<%=Session["bar"]%>');
}
</script>