How to access session variable?

E

Eric

Hi,

I've a problem with trying to retrieve a session variable in an include file.

Basically, the main asp creates a session variable:

<% Session("var1") = "Hello" %>

And then when I click on a button it refers to the include file, which I
believe is all client-side code as there are no server <% %> tags.

I want to be able to use this session variable in the include file, how do I
do this?

If I try retrieving this session variable with Session("var"), it will come
up with an error saying that it has a type mismatch 'Session'.

The session state is enabled in IIS manager and appears to be working with
the other session variables in asp's not written with the server tags <% %>.

The include file has the .asp extension and has two language sections and I
want to use the session variable within the vbscript language tag like this:

<Script Language="JavaScript">
...
...
...
</Script>

<Script Language="VBScript">

If Not Session("Var") Then
...
...
End If

</Script>

I'm getting the type mismatch: "session" error on the IF block in the above
sample.

Thanks for your help in advance,
Eric.
 
R

Roland Hall

: Hi,
:
: I've a problem with trying to retrieve a session variable in an include
file.
:
: Basically, the main asp creates a session variable:
:
: <% Session("var1") = "Hello" %>
:
: And then when I click on a button it refers to the include file, which I
: believe is all client-side code as there are no server <% %> tags.
:
: I want to be able to use this session variable in the include file, how do
I
: do this?
:
: If I try retrieving this session variable with Session("var"), it will
come
: up with an error saying that it has a type mismatch 'Session'.
:
: The session state is enabled in IIS manager and appears to be working with
: the other session variables in asp's not written with the server tags <%
%>.
:
: The include file has the .asp extension and has two language sections and
I
: want to use the session variable within the vbscript language tag like
this:
:
: <Script Language="JavaScript">
: ...
: ...
: ...
: </Script>
:
: <Script Language="VBScript">
:
: If Not Session("Var") Then
: ...
: ...
: End If
:
: </Script>
:
: I'm getting the type mismatch: "session" error on the IF block in the
above
: sample.

You may be able to pass the session variable value to client-side code but
to access it directly you probably need to run it server-side.

<%

dim myvar
myvar = session("Var")
%>
<script type="text/javascript">
var myvar = <%=myvar%>;
alert(myvar);
</script>
<script type="text/vbscript">
dim myvar : myvar = <%=myvar%>
msgbox myvar
</script>

or

<script type="text/vbscript" runat="server">
dim myvar
myvar = session("Var")
</script>

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top