[thelist] Sharing data between ASP and JavaScripts

David.Cantrell at Gunter.AF.mil David.Cantrell at Gunter.AF.mil
Wed Feb 26 08:48:11 CST 2003

> You hit what I want to do right on the head.  I don't want to
> give up so easy, though.


> I have an idea.  If I have a Session() variable that I can
> set to 1 if the user wishes to quit, then I can test for that
> in my do ... loop.  The only problem is how to set the
> Session() variable inside a javascript or vbscript.

You can't. By Javascript I assume you mean on the client, not Jscript on the
server? If client, then no, definitely not -- they are two totally separate
processes. Once the client hands off processing to the server, the only
thing it can do is wait for a response. It can't interact with a running
process on the server.

Doing anything else would require a stateful connection, which is exactly
what HTTP does NOT provide. Because once that Javascript fired and sent some
more data to the server, the server thinks it's a *completely new*
connection, and starts another process while the other one is running. And
when the first completes, you never know, because you broke the existing
connection by sending more data and creating a new connection.

Does that make sense at all? You maintain a connection to the server for one
reason only, to receive data. This is the way HTTP is designed.

> <script language="javascript">
> function funcName()
> {
>    var s = <%=Session("varname")%>;
>    .
>    .
>    return true;
> }
> </script>

The reason you can do this is that the ASP process executes the ASP script
and dumps the output to the Response stream, which in turn is handed back to
the IIS process which writes the result to the browser. So the Session
variable above is being written *on the server in memory*, then the final
HTML page is sent to the end user's browser. Don't confuse the two

> How about going the other way? If I could set a session
> variable from within a javascript I would be all set.
> Perhaps with remote scripting???

Remote scripting creates a new connection. These aren't called "dumb
browsers" for nothing. :)


More information about the thelist mailing list