Skip to main content
January 21, 2010
Question

Passing Session variables (ASP.NET)

  • January 21, 2010
  • 2 replies
  • 836 views

Hi,

I've been working on a site for quite a while and am a fair way in using Javascript. However I thought I'd check out a bit of asp.net as it has quite a few functions that seem easier to implement than in Javascript.

I have a login page created using the built-in server behaviours that sets a session variable in Javascript using the following line of code:

Session("MM_Username") = MM_valUsername;

This variable is avalable to all other javascript pages and I can disply the variable on a page by placing this lin eof code within the HTML:

<%= Session("MM_Username") %>

However the one page that I have created using vb.net will not display the variable. The code I'm using is this:

<% =Session("MM_Username")%>

Is there a reason for this or am I just doing something wrong?

Thanks in advance

Dan

This topic has been closed for replies.

2 replies

Participating Frequently
January 21, 2010

This doesn't make sense. You say you are using a "server behavior" that sets a "client side session" using javascript. Are you sure this isn't ASP/JScript?

January 22, 2010

Hi bregent, thanks for taking the time to read and respond.

I suspect I'm using the wrong terminology! The login page where the session variable is set has an ASP extention, but according to the first line of code its Javascript

<%@LANGUAGE="JAVASCRIPT"%>

Soooo...errrrr.... Jscript or javascript... ??

Cheers

Dan

January 21, 2010

Ahhhh ha! I think I've found the answer but would like someone who knows what they're on about to confirm for me.

I believe the reason I can't pass a variable is because Javascript is executed on the browser, so the session variable is set on the local PC.

ASP.net on the other hand is executed on the server. So a session variable set in Javascript code has no way of getting to the server ?

So the only way I can see that I can pass a variable would be to use a QueryString which would be picked up by the ASP page... I think

Cheers

Dan