How can I set session variables with JavaScript

I would like to set a couple of session variables when I click an image on the page. The session variables will be equal to textboxes on the same page as the image: Here is the tag for the image.

<a onclick="'../../Process.aspx','cal','width=490,height=420,left=500,top=180,scrollbars=no')"

href="javascript:;"><img alt="Process" src="../../images/register.gif" style="border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none" id="IMG1" onclick="return IMG1_onclick()" /></a>


script type="text/javascript" src="../../NoPostBacks.js">


IMG1_onclick() {

Session("Amount") = Me.txtAmount.Text

Session("Zip") =Me.txtZip.Text



Thank you

1/17/2007 1:40:44 AM 8807 articles. 0 followers. Follow

8 Replies

Similar Articles

[PageSpeed] 59

cant unless you  use ajax.

Jared Roberts
Lead Application Developer
1/17/2007 2:59:22 AM
No, sessions can't be accessed by javascript directly. It's stored on server, while javascript is running on client.
But can be done indirectly, e.g., store it in a hidden filed, submit it to the server, and retrieve and assign the values in hidden filed to session.
Hope it helps.
1/17/2007 6:13:07 AM

Is it possible to pass the values of a couple of textboxes from one form to another without using querystring, session, ajax, or java?

What Ineed is when a page opens it invisiably gets the value of a couple of textboxes from the previous page.

I appreciate any suggestions.

Thank you

1/17/2007 1:54:07 PM
There is a new feature called cross page postback in 2.0, it may meet your need.
Working with Cross Page Posting Using ASP.NET 2.0
1/18/2007 1:05:17 AM

Hi Jack,

I discovered that client and server side got communicated better than what I was originally thinking, by using Response and Request object, web app maintences client and server data integrity very well. I do verified that on server side when you want to read client data, e.g. a cookie, you can use Request.Cookie; and vise versa when you want to set a client side cookie, use Response.Cookie.

 So i dare this assumption to session, and did following client side trying in Javasript, amazingly found, it succeeded.

<%Session["tbActionItem" + "1"] = "abc"; %>

However, I am stocked when I use: 

<%Session["tbActionItem" + "(i + 1)"] = "abc"; %>  // i is a var in the javascript.

So my question is how to involve a javascript variable in a inbed session index? 

 Anyone get answer?

6/11/2008 9:08:15 PM

here you go

 var myvar = "Hey Buddy";

'<%Session["temp"] = "' + myvar +'"; %>' ;

alert('<%=Session["temp"] %>');

 Happy Programming...!

Muhammad Hassan
11/15/2008 6:59:02 PM
var myvar = "Hey Buddy";

'<%Session["temp"] = "' + myvar +'"; %>' ;

alert('<%=Session["temp"] %>');

Does this really work?  the javascript is executing on the client side.

Peter Kellner and blogging at
11/15/2008 11:55:09 PM

yeeeh it works for me why dont you run it. Make sure to Mark as answer if it works for you too.


Thank you

Muhammad Hassan
11/16/2008 5:32:18 AM

Web resources about - How can I set session variables with JavaScript -

JavaScript Kit- Your comprehensive JavaScript, DHTML, CSS, and Ajax stop
Your comprehensive JavaScript, DHTML, CSS, and Ajax stop

Let's Code: Test-Driven Javascript by James Shore — Kickstarter
James Shore is raising funds for Let's Code: Test-Driven Javascript on Kickstarter! A screencast series focusing on rigorous, professional Javascript ...

Eloquent JavaScript: A Modern Introduction to Programming
... and pragmatics. I loved the tutorial-style game-like program development. This book rekindled my earliest joys of programming. Plus, JavaScript! ...

JavaScript - Wikipedia, the free encyclopedia
programming styles. JavaScript was formalized in the ECMAScript language standard and is primarily used in the form of client-side JavaScript ...

Open Directory - Computers: Programming: Languages: JavaScript: Tools: Obfuscators
... editor - report abuse/spam - help the entire directory only in Tools/Obfuscators Description Top : Computers : Programming : Languages : JavaScript ...

Facebook File-Transfer App Pipe Relaunches, Now Works Via JavaScript, WebRTC
... allowed Facebook users to send and receive files up to 1 gigabit in size. A new version of Pipe debuted Monday, and the app now works via JavaScript ...

Under the Hood: The JavaScript SDK - The use of polyfills - Facebook
Facebook Engineering hat eine Notiz mit dem Titel Under the Hood: The JavaScript SDK - The use of polyfills geschrieben. Du kannst den vollständigen ...

The Facebook SDK for JavaScript provides a rich set of client-side functionality for adding Social Plugins, making API calls and implementing ...

Senior Front-End Developer (Javascript and AJAX)
Company: Sometrics Category: Software Development Location: Los Angeles, CA How to Apply: Description: We are looking for ...

Badass JavaScript (@badass_js) on Twitter
WebGLWorker is an open source library that allows using WebGL from Web Workers. Great work as always from @kripken .… ...

Resources last updated: 3/16/2016 10:42:31 PM