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="window.open('../../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">

function

IMG1_onclick() {

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

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

}

</

script>
Thank you

Jackxxx
-1
Jackxxx
1/17/2007 1:40:44 AM
asp.net.state-management 8807 articles. 0 followers. Follow

8 Replies
34361 Views

Similar Articles

[PageSpeed] 6

cant unless you  use ajax.

http://www.jguru.com/faq/view.jsp?EID=1300197


Jared Roberts
Lead Application Developer
0
rojay12
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
Raymond
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

Jackxxx
-2
Jackxxx
1/17/2007 1:54:07 PM
There is a new feature called cross page postback in asp.net 2.0, it may meet your need.
Working with Cross Page Posting Using ASP.NET 2.0
1
Raymond
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?
 

-1
haiwag
6/11/2008 9:08:15 PM

here you go

 var myvar = "Hey Buddy";

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

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

 Happy Programming...!


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

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

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

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


Peter Kellner
http://73rdstreet.com and blogging at
http://PeterKellner.net
MVP, ASP.NET
-1
pkellner
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
0
MuhammadHassan
11/16/2008 5:32:18 AM
Reply:

Web resources about - How can I set session variables with JavaScript - asp.net.state-management

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 ...

JavaScript
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: jobs@sometrics.com 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 . blog.mozilla.org/research/2014/… ...

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