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.
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.
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?
Jackxxx
Contributor
3060 Points
2788 Posts
How can I set session variables with JavaScript
Jan 17, 2007 12:40 AM|LINK
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>Jackxxx
rojay12
Contributor
4065 Points
738 Posts
Re: How can I set session variables with JavaScript
Jan 17, 2007 01:59 AM|LINK
cant unless you use ajax.
http://www.jguru.com/faq/view.jsp?EID=1300197
Lead Application Developer
Raymond Wen ...
All-Star
32101 Points
3764 Posts
Re: How can I set session variables with JavaScript
Jan 17, 2007 05:13 AM|LINK
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.
Jackxxx
Contributor
3060 Points
2788 Posts
Re: How can I set session variables with JavaScript
Jan 17, 2007 12:54 PM|LINK
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.
Jackxxx
Raymond Wen ...
All-Star
32101 Points
3764 Posts
Re: How can I set session variables with JavaScript
Jan 18, 2007 12:05 AM|LINK
Working with Cross Page Posting Using ASP.NET 2.0
haiwag
Member
20 Points
9 Posts
Re: How can I set session variables with JavaScript
Jun 11, 2008 09:08 PM|LINK
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?
MuhammadHass...
Member
21 Points
31 Posts
Re: How can I set session variables with JavaScript
Nov 15, 2008 05:59 PM|LINK
here you go
var myvar = "Hey Buddy"; '<%Session["temp"] = "' + myvar +'"; %>' ;alert(
'<%=Session["temp"] %>');Happy Programming...!
pkellner
All-Star
24042 Points
3625 Posts
ASPInsiders
Moderator
MVP
Re: How can I set session variables with JavaScript
Nov 15, 2008 10:55 PM|LINK
Does this really work? the javascript is executing on the client side.
http://peterkellner.net
Microsoft MVP • ASPInsider
MuhammadHass...
Member
21 Points
31 Posts
Re: How can I set session variables with JavaScript
Nov 16, 2008 04:32 AM|LINK
yeeeh it works for me why dont you run it. Make sure to Mark as answer if it works for you too.
Thank you
rajenderchua...
Member
2 Points
1 Post
Re: How can I set session variables with JavaScript
May 15, 2009 07:41 AM|LINK
no realy it is not working like a session it is just working like normal variable.
i need to set session value in one js method and use it on body load of the next page
i am doing this on master page for making tab selected for current page