SunQuest
 
           JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old July 9th, 2005, 02:31 PM
lonewolf27 lonewolf27 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: South Africa
Posts: 21 lonewolf27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 27 sec
Reputation Power: 0
Cool Possible to assign session variable value in JavaScript?

First off, great forum and site. Keep up the good work!

Just a quick question: Is it possible to assign a session variable's value in Javascript?

I am aware of something like:

var a;
a = <%=Session("name")%>;

But can you do it the other way around? Something like:

var a;
a = "test";
<%Session("name")=%> = a; ??

Thanks for reading my first post, and sorry in advance if I've missed this solution in another post...late night and my eyes are sore from the strains of ASP.NET

Reply With Quote
  #2  
Old July 10th, 2005, 06:25 PM
ChiefWigs1982's Avatar
ChiefWigs1982 ChiefWigs1982 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: I have emerged from the place of spells and fairies
Posts: 97 ChiefWigs1982 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 17 h 35 m 12 sec
Reputation Power: 4
No, not directly. Your session vars are controlled by the server,
JS runs client side, and as such cannot modify the vars directly.

You need to make server requests using POST or GET and hidden
iframes, or XMLHTTPRequest() calls to send data from the JS to
the server, and then have your ASP.NET code handle the vars.
__________________
Sinthetic - Alternative UK Hiphop: What's the worst that could happen?

"I'm going to become rich and famous when I invent a device that allows you to stab people in the face over the internet"



Reply With Quote
  #3  
Old July 11th, 2005, 08:31 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
I'm curious as to why you would want the server's session variable in your clientside Javascript...

There's likely a better solution.

Reply With Quote
  #4  
Old July 13th, 2005, 11:36 AM
lonewolf27 lonewolf27 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: South Africa
Posts: 21 lonewolf27 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 37 m 27 sec
Reputation Power: 0
No reason in particular, was just using javascript on a project 'cos it seemed the best solution for the problem. just trying to get values across pages is all

Thanks for the help guys. Guess this was one of those questions which bug you until you get an answer, even if the answer is just "you cant do it"

anyways, appreciate it, thanks again...

Reply With Quote
  #5  
Old July 14th, 2005, 09:33 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 4 m 48 sec
Reputation Power: 8
Not so much the fact that "you cant do it" ... I just don't see much reason TO do it...
Session variables are managed on the server, they are carried with the user across all pages (so long as the browser complies)...
Javascript being client side, could have no use for the session ID and stuff.

On a second-read of your original post, I realize it isn't the session ID you are wanting to use... in which case the answer is yes...
Quote:
Originally Posted by lonewolf27
I am aware of something like:

var a;
a = <%=Session("name")%>;

But can you do it the other way around? Something like:

var a;
a = "test";
<%Session("name")=%> = a;

You can do both of those examples, however the second one may be a little unpredictable...
It would be easier to keep the variable names uniform for all users...

Reply With Quote
  #6  
Old December 28th, 2007, 07:05 AM
SinghSamsher SinghSamsher is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2007
Posts: 1 SinghSamsher User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 31 sec
Reputation Power: 0
Session using javascript

you can use
<%session["stringName"] = HiddenFieldname%>

Hidden field must be asp.net control

Reply With Quote
  #7  
Old March 27th, 2008, 09:51 AM
pc.huff pc.huff is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 1 pc.huff User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 13 sec
Reputation Power: 0
Actually I have a need for it. I'm dynamically generating controls server side, then I'm doing stuff to their styles in javascript. On postback I recreate them and populate them from session variables, but some stuff I may need to re-populate after postback from javascript to prevent a page refresh.

Reply With Quote
  #8  
Old May 29th, 2008, 02:12 PM
lkeel lkeel is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 1 lkeel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 40 sec
Reputation Power: 0
I have figured out how to do this using the AJAX.NET ScriptManager, Webmethods and making PageMethod calls. My problem is that I have now implemented Security and I am getting an Authentication Error when I make the PageMethod call. I would really appreciate it if anyone could shed some light on how to get around this problem.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Possible to assign session variable value in JavaScript?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway