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:
  #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: 10
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,886 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 19 m 35 sec
Reputation Power: 14
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,886 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 19 m 35 sec
Reputation Power: 14
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
  #9  
Old July 25th, 2008, 04:59 AM
Neeraj of Siwan Neeraj of Siwan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 2 Neeraj of Siwan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 19 sec
Reputation Power: 0
Angry assign a session variable's value in Javascript?

var a;
a = <%=Session("name")%>;
will not work in case we are using an external JavaScript File

Reply With Quote
  #10  
Old July 25th, 2008, 05:02 AM
Neeraj of Siwan Neeraj of Siwan is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Posts: 2 Neeraj of Siwan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 19 sec
Reputation Power: 0
var a;
a = <%=Session("name")%>;
will not work in case we are using an external JavaScript File

Reply With Quote
  #11  
Old June 23rd, 2010, 06:13 AM
pholenko pholenko is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Posts: 1 pholenko User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 18 sec
Reputation Power: 0
Try this!

var realm;
function load(){
realm = '<%=session.getAttribute("realm")%>';

Reply With Quote
  #12  
Old October 27th, 2011, 09:03 AM
IT-Maverick IT-Maverick is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2011
Posts: 1 IT-Maverick User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 32 sec
Reputation Power: 0
Javascript $_SESSION variable with PHP

To use a SESSION variable with php and Javascript use

var a = <?php echo $_SESSION['var_name']; ?>

Reply With Quote
  #13  
Old November 3rd, 2011, 09:06 PM
song387zhuzhao song387zhuzhao is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 1 song387zhuzhao User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 18 m 51 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
  #14  
Old March 12th, 2012, 09:48 PM
hhschjkm0 hhschjkm0 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 4 hhschjkm0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 55 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.URL
URL
URL

Reply With Quote
  #15  
Old March 16th, 2012, 01:52 AM
hhvdketi1 hhvdketi1 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2012
Posts: 5 hhvdketi1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 m 57 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
  #16  
Old April 28th, 2012, 12:50 AM
matin2gray matin2gray is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 1 matin2gray User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 35 sec
Reputation Power: 0
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
  #17  
Old May 1st, 2012, 04:25 AM
penaw52 penaw52 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2012
Posts: 1 penaw52 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 9 sec
Reputation Power: 0
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
  #18  
Old December 5th, 2012, 01:44 AM
corbidougu corbidougu is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 5 corbidougu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 53 sec
Reputation Power: 0
the server's session variable in your clientside Javascript.

Reply With Quote
Reply

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


Developer Shed Advertisers and Affiliates


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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap