Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using Session object in Javascript on Win 2003

0 views
Skip to first unread message

Rob

unread,
Jan 3, 2007, 10:23:01 AM1/3/07
to
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


*** Sent via Developersdex http://www.developersdex.com ***

VK

unread,
Jan 3, 2007, 10:48:46 AM1/3/07
to

Rob wrote:
> 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.

VK

unread,
Jan 3, 2007, 10:57:28 AM1/3/07
to

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?

Julian Turner

unread,
Jan 3, 2007, 11:15:57 AM1/3/07
to

Rob wrote:

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

Rob

unread,
Jan 3, 2007, 11:51:04 AM1/3/07
to
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

VK

unread,
Jan 3, 2007, 1:01:38 PM1/3/07
to
Julian Turner wrote:
> 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.

Evertjan.

unread,
Jan 3, 2007, 1:39:07 PM1/3/07
to
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.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Chad.B...@gmail.com

unread,
Jan 3, 2007, 3:47:43 PM1/3/07
to
> 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

0 new messages