By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,333 Members | 1,850 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,333 IT Pros & Developers. It's quick & easy.

How to access session variable?

P: n/a
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.
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Eric" <Er**@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
: 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
Jul 22 '05 #2

P: n/a
there may be a way to put your server side session variable into something
so client side code can read it but I have never done it.
generallly you write it server side and read it server side

http://www.powerasp.com/content/code...-variables.asp
"Eric" <Er**@discussions.microsoft.com> wrote in message
news:6D**********************************@microsof t.com...
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.

Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.