473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

How to access session variable?

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
2 13502
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Peter | last post by:
L.S. I am developing a PHP-login script (on Lycos Tripod) that uses Session to pass on variables. Below is the entire (stripped) structure that I use. It opens a page where you can Set and Read...
3
by: Geoff Winsor | last post by:
Hi, I am experiencing a problem with recalling a session variable which stores whether a person is logged in to a "members only" section of a website. This area of the site has been working...
2
by: George | last post by:
Hi In my ASP.NET project, I have a session variable that is assigned on a login page. In another .cs file (in another directory), I'm trying to use if((string)Session == "something" When I...
2
by: Stu | last post by:
Hi, I am trying to access session variable value from the 'Application_BeginRequest' handler in the global asax file but get the message - 'Session state not available in this context'. I have...
13
by: Nagib Abi Fadel | last post by:
Is it possible to create a session variable for each user in Postresql ?? Thx
4
by: Diffident | last post by:
Hi All, I am trying to perform a non-CPU bound operation in an asynchronous fashion using 'Thread' and a delegate. Basically, I am spawning a thread using ThreadStart and Thread. My non-CPU...
1
by: jesibl | last post by:
Hi All, I have an ASP .NET 2.0 web based app which should change content based on a variable passed in the query string. Let's say the variable is called ID and the variations are A, B and C. ...
3
by: madhuribond | last post by:
Hi All, I need your help, i have 3 html pages and one aspx page.After visiting the aspx page it creates one session variable this variable i want to access in all my html pages thru anyway....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.