|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 ![]() |
|
#2
|
||||
|
||||
|
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? |
|
#3
|
||||
|
||||
|
I'm curious as to why you would want the server's session variable in your clientside Javascript...
There's likely a better solution. |
|
#4
|
|||
|
|||
|
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... |
|
#5
|
||||
|
||||
|
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:
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... |
|
#6
|
|||
|
|||
|
Session using javascript
you can use
<%session["stringName"] = HiddenFieldname%> Hidden field must be asp.net control |
|
#7
|
|||
|
|||
|
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.
|
|
#8
|
|||
|
|||
|
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.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > Possible to assign session variable value in JavaScript? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|