title: ASP.NET Change session value when change page
body: <p>Hello community of stack overflow, this is my first question and I will try be clear.
  Im developing a projet that is a school work in ASP.NET C#.</p>
  
  <p>Im trying to change the value of a SESSION when the user change the WebForm by any button or by the URl bar. I already tried that with javascript code:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
          window.onbeforeunload = confirmExit;
  
          function confirmExit() {
              '&lt;%Session["teste"] = "changed"; %&gt;';
          }
  
   &lt;/script&gt;
  </code></pre>
  
  <p>For testing In the WebForm1 I give to the SESSION an value at the PageLoad event: </p>
  
  <pre><code>Session["teste"] = "teste";
  </code></pre>
  
  <p>Then when I go to WebForm2 by the URl bar and I print the value of the SESSION to a label the result is "changed", the value that I want, but if I go to the WebForm2 by an ASP button the value of the SESSION still be "teste". Somebody know how I can solve my issue? Thanks.</p>