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

Can you access Session Variables from Client Side Script?

P: n/a
if so, how?

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
No, you have to pass them to client, for example in a hidden input element.

Eliyahu

"Craig G" <craig.gamble@y_arrasoftware.com> wrote in message
news:ur****************@TK2MSFTNGP12.phx.gbl...
if so, how?

Nov 19 '05 #2

P: n/a
Craig G wrote:
if so, how?

You cannot access Session directly from client side script. However, you
can generate JavaScript code to assign the value of the Session variable
to a client side variable. If you change the client side variable,
you'll have to post the new value back in order to update the Session.

Here is a simple example which creates a JavaScript variable with the
value of a Session variable:
<%@ Page language="c#" AutoEventWireup="true" %>
<script runat="server">
void Page_Load()
{
Session["MySessionVar"]="Hello world";
}
</script>
<html>
<script language="JavaScript">
var mySessionVar="<%= Session["MySessionVar"] %>";
</script>
<body>
<form runat="server"></form>
</body>
</html>

Anders Norås
http://dotnetjunkies.com/weblog/anoras/
Nov 19 '05 #3

P: n/a
nice one, cheers for the help!

"Anders Norås" <an**********@objectware.no> wrote in message
news:eR**************@TK2MSFTNGP09.phx.gbl...
Craig G wrote:
if so, how?

You cannot access Session directly from client side script. However, you
can generate JavaScript code to assign the value of the Session variable
to a client side variable. If you change the client side variable,
you'll have to post the new value back in order to update the Session.

Here is a simple example which creates a JavaScript variable with the
value of a Session variable:
<%@ Page language="c#" AutoEventWireup="true" %>
<script runat="server">
void Page_Load()
{
Session["MySessionVar"]="Hello world";
}
</script>
<html>
<script language="JavaScript">
var mySessionVar="<%= Session["MySessionVar"] %>";
</script>
<body>
<form runat="server"></form>
</body>
</html>

Anders Norås
http://dotnetjunkies.com/weblog/anoras/

Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.