473,473 Members | 1,874 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

session variables, accessing from client side java script

hi,

is a session varibale acessible for reading and writing from client side
javascript?

say i have a session variable called 'Session("Color")', and i want to
read/write to it, how would i refere to it say in a onclick event?

i would appreciate a snipet of code.

thanks

ray
Nov 19 '05 #1
6 2510
No, it is not accessible from client side javascript. Session information is
stored on the server.

"ray well" <no****@nospam.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
hi,

is a session varibale acessible for reading and writing from client side
javascript?

say i have a session variable called 'Session("Color")', and i want to
read/write to it, how would i refere to it say in a onclick event?

i would appreciate a snipet of code.

thanks

ray

Nov 19 '05 #2
If you wish to do so then you need to store the information in
something that is sent to the client side. The easiest way to do this
is to use an <input type="hidden" id="hdfMyColor" runat="server" />
then in your codebehind define the variable as such
or
Protected WithEvents hdfMyColor As
System.Web.UI.HtmlControls.HtmlInputHidden
Attach an event handler to the PreRender method and in there set the
HtmlInputHidden's value to the session value
Private Sub Page_Render(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
hdfMyColor.Value = Session("Color")
End Sub
now you would simply go
<script type="text/javascript">
var colorHolder = document.getElementById("hdfMyColor");
var color = colorHolder.value;
</script>

Nov 19 '05 #3
Another method to doing that is to use RegisterClientScriptBlock to set
the variable manually through javascript code.
Private Sub Page_Render(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.PreRender
RegisterClientScriptBlock("ddd", "<script type='text/javascript'> var
color = '" + Session("Color") + "';</script>")
End Sub
This method may be alot easier

Nov 19 '05 #4
No, Session variables reside on the server. If you want access, you will
need to postback to the server for your on click event.

bill

"ray well" <no****@nospam.com> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
hi,

is a session varibale acessible for reading and writing from client side
javascript?

say i have a session variable called 'Session("Color")', and i want to
read/write to it, how would i refere to it say in a onclick event?

i would appreciate a snipet of code.

thanks

ray

Nov 19 '05 #5
Or use any of my provided methods

Nov 19 '05 #6
How does either of your methods help ray meet his requirements of reading
and writing a session variable?

bill
"re****@community.nospam" <ma**********@gmail.com> wrote in message
news:11********************@f14g2000cwb.googlegrou ps.com...
Or use any of my provided methods

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Mimi | last post by:
Hello, I am having trouble using the session vars in PHP 4.3.9 OS: Win XP Prof Web Server IIS (is local and there are no links to other servers from the web pages I work on) Browser: IE 6.0 ...
5
by: DS | last post by:
In client-side script (<script> codes </script>), how can set / get session variables' values? Pls advise. DS
1
by: Vetrivel | last post by:
Application architecture : Develop interface between two existing systems, a. Enterprise CRM system b. Web based intranet system. Environment : Intranet Server : IIS and ASP. Script :...
2
by: Eric | last post by:
Hi, I've a problem with trying to retrieve a session variable in an include file. Basically, the main asp creates a session variable: <% Session("var1") = "Hello" %> And then when I click...
2
by: Bonj | last post by:
H I've got the following problem - I need to have an aspx page with two frames, although the question isn't necessarily about the workings of the frames, more session variables... the frames consist...
7
by: Seth | last post by:
I have noticed that the id of my session object changes when I switch from a non-secure to a secure connection. What I'm trying to do: I have a cookie that is built on the non-secure side of...
5
by: jb | last post by:
*Please* help --- I'm tearing my hair out. I want to use sessionstate in a webservice, accessed from a client, written in script (JScript, InfoPath). I have written my webservice (C# .NET). I...
6
by: Marcus | last post by:
I have an ASP.Net 2.0 app that needs to jump out onto another web server running a java server page website (Apache TomCat 4.1.12) that I control. I hate that it needs to do this, but we are using...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.