Using Session object in Javascript on Win 2003

R

Rob

Hi,
I'm getting an error on my login page when using Javascript session
object. It works on the development server so I'm wondering if there is
a setting in IIS to allow using sessions on the server.

When the user clicks on the submit button after entering their username
and password, it calls a function (below) and I get an "Object expected"
javascript error.

This is the function:

function ftn_process()
{
var str_uid = document.login.str_uid.value;
var str_pswrd = document.login.str_pswrd.value;
if (str_uid != "" && str_pswrd != "")
{
Session("UserID") = ""
Session("Logged") = "";
Session("userLevel") = -1;
document.forms("login").submit();
}
}

I get the error at Session("UserID");
Does anybody have any ideas on this problem?

Yhanks
Rob
 
V

VK

Rob said:
Session("UserID") = ""
I get the error at Session("UserID");
Does anybody have any ideas on this problem?

Possibly because you didn't define Session function anywhere in your
code.
It has to be a function because you are calling it in the function
contect.
 
V

VK

VK said:
Possibly because you didn't define Session function anywhere in your
code.
It has to be a function because you are calling it in the function
contect.

Oops... Correction: you cannot assign to function results. This way
Session("UserID") = "";
has no sense whatsoever.

Could you provide a link to get an idea of what are you doing?
 
J

Julian Turner

Rob said:
Hi,
I'm getting an error on my login page when using Javascript session
object. It works on the development server so I'm wondering if there is
a setting in IIS to allow using sessions on the server.

When the user clicks on the submit button after entering their username
and password, it calls a function (below) and I get an "Object expected"
javascript error.

This is the function:

function ftn_process()
{
var str_uid = document.login.str_uid.value;
var str_pswrd = document.login.str_pswrd.value;
if (str_uid != "" && str_pswrd != "")
{
Session("UserID") = ""
Session("Logged") = "";
Session("userLevel") = -1;
document.forms("login").submit();
}
}

I get the error at Session("UserID");
Does anybody have any ideas on this problem?

Yhanks
Rob

Hi

The Session object is a host object (i.e. not native) that is made
available to JavaScript code processed on the server in an ASP
pre-processing page.

Contrary to VK's comment, under ASP I believe the Session object's
properties are accessed using ' ( ) ' notation, so in an ASP page,
Session("UserID") = "" is I think valid.

However, looking at the above code, it looks like you are running this
in a client web page. The ASP Session object cannot be acessed by code
running on the client. It is only available to that JavaScript which
runs on the server **before** the ASP page is sent to the client.

Regards

Julian
 
R

Rob

Thanks Julian,

The problem is that this was working on the development server but when
we moved it to production, that's when I get the error so that's why I
thought it was an IIS setting issue.
I would send a link but it's an intranet application.

The page language is javascript as well,
<% @Language="javascript" %>

but my function is within a <script> block.

I don't know if that makes a difference.

Regards
Rob
 
V

VK

Julian said:
Contrary to VK's comment, under ASP I believe the Session object's
properties are accessed using ' ( ) ' notation, so in an ASP page,
Session("UserID") = "" is I think valid.

I meant that this statement is not valid for ECMAScript-compliant
engines including javascript. Whatever is valid for server-side ASP
instructions is beyond of anyone's power but Microsoft.
 
E

Evertjan.

Rob wrote on 03 jan 2007 in comp.lang.javascript:
Thanks Julian,

The problem is that this was working on the development server but when
we moved it to production, that's when I get the error so that's why I
thought it was an IIS setting issue.
I would send a link but it's an intranet application.

The page language is javascript as well,
<% @Language="javascript" %>

but my function is within a <script> block.

I don't know if that makes a difference.

Learn to understand the difference between
server side executed code and clientside executed code.

Serverside code is processed first
and the resulting html [perhaps with client side code]
is sent as a stream to the clientside, the browser mostly,
and the clientside cannot even see the serverside code.

============ test.asp ==================
<% @Language='javascript' %>
<br>
<%
if (7>5) response.write('Hello world');
%>
<br>
<script type='text/javascript'>
document.write('good morning.');
</script>
=========================================

will send this html to the browser:

=======================================
<br>
Hello world
<br>
<script type='text/javascript'>
document.write('good morning.');
</script>
========================================

And the browser will display:

=======================================

Hello world
good morning.
========================================

Session variables are serverside variables,
and only their containing values can be sent to the client.

<%
response.write( session('theName') );
%>

So the session object only exist in the serverside code.
 
C

Chad.Burggraf

The page language is javascript as well,
<% @Language="javascript" %>

but my function is within a <script> block.

I don't know if that makes a difference.

Regards
Rob

The problem is most likely due to a missing runat="server" attribute in
your script tag. Your tag should look like:

<script type="javascript" runat="server">
...
</script>

Cheers
Chad
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top