title: (ASP classic) Stop/Block execution of rest of code without interrupt Javascript execution
body: <p>I am running in an issue similar to the one in <a href="https://stackoverflow.com/questions/279066/looking-for-a-hack-to-prevent-rewriting-an-app-without-using-session-variables">this other thread</a> and I'm getting short of ideas so I would really appreciate any help !</p>
  
  <p>Here's the thing : 
   We have an ASP application that uses session variables and has to deal with session merging due to multitabs (IE8). </p>
  
  <p>After many many many tries, I've came to the following implementation : </p>
  
  <ol>
  <li><p>I'm setting an ID to each browser's TAB (I'm using the <a href="http://msdn.microsoft.com/en-us/library/cc197062%28VS.85%29.aspx#_session" rel="nofollow noreferrer">sessionStorage</a> for that) on client-side. </p></li>
  <li><p>In order to make it available from server-side (since I could not find any other way) I'm saving it in a cookie and reloading the page.</p></li>
  <li><p>Finally on my ASP pages, I'm getting this ID from the cookie and using it as prefix of all the sessions variables on the application. </p></li>
  </ol>
  
  <p>Here's a short example</p>
  
  <p>Javascript (Inserted at the very beginning of every asp files)</p>
  
  <pre><code>    LoadJs();
  
      // Cookie and TabID handler
      function LoadJs()
      {
          if (getInternetExplorerVersion() &lt;= 6)
          {
              //alert("Exit..... old browser version : " + getInternetExplorerVersion());
              return;
          }
  
          if (sessionStorage.TabID)
          {
              // Check value in cookie 
              var tabIdinCookie = readCookie("tabid");
  
              // if ID in cookie not the same as ID in session update cookie and
              // refresh the page to update values in server-side
              if(!tabIdinCookie || (tabIdinCookie &amp;&amp; tabIdinCookie != sessionStorage.TabID)) 
              {
                  createCookie("tabid",sessionStorage.TabID);
                  ReloadPage();
              }
          }
          else
          {
              // Create random ID
              var currentTime = new Date();    
              sessionStorage.TabID = currentTime.getTime();
              // Save ID to cookie
              createCookie("tabid",sessionStorage.TabID);
              createCookie("usingIE8",true,1);
  
              // Refresh the page to make it available from server-side
              ReloadPage();
  
           }
           return true;
      }
  
      // Redirect to the same page to refresh data at server-side
      function ReloadPage()
      {
          window.location.reload(true);
      }
  </code></pre>
  
  <hr>
  
  <p>Then, the ASP code : </p>
  
  <pre><code>&lt;%
     Dim Nm 
     Nm=""
  
  
  response.Write("&lt;br&gt;Reading from cookie....")
  
     if (Request.cookies("usingIE8") &lt;&gt; "" )then
          if (Request.cookies("tabid") = "") then
              'response.Write("&lt;br&gt;No cookie")
              'response.flush() 
              ' WHAT TO DO HERE ????
          else
              Response.Write("&lt;br&gt;Cookie FOUND&lt;br&gt;")
              Nm = Request.cookies("tabid")
          end if
     end if 
  
  
  
  
  if (Session(Nm + "LogonTime")="") then
      Response.Write("&lt;br&gt;&lt;b&gt;Updating session&lt;/b&gt;&lt;br&gt;")
      Session(Nm + "LogonTime") = Now
      UpdateInDB(Session(Nm + "LogonTime"))
      ' Do other stuffs
  end if   
  </code></pre>
  
  <p>%></p>
  
  <hr>
  
  <p>I was pretty proud about finally getting a workaround to the issue, but I realized that when a page do a post action, all code ASP is rendered (with the wrong prefix-ID) and executed (database operations included) before right TabID can be updated on the cookie and page can be reloaded by javascript. I mean that all my page code is being executed twice, once before and once again after the refresh... :-|</p>
  
  <p>Does anyone think it could be possible to implement smthg like a Response.End() to prevent the rest of the code ASP to execute if I can identify I have to refresh the page without killing at the same time the javascript execution ? Or to wait for all javascript execution before any other action on the page ?</p>
  
  <p>I'm stuck here and it make me cry to have to stop here ! There must be a solution... If I can fin a fix, it would be to be applied to many ASP (3.0) applications that won't be upgraded to ASP.NET before at least 3 or 5 years.</p>
  
  <p>Thanks in advance,</p>