Solved

How to write value to Session object

Posted on 2002-05-19
8
272 Views
Last Modified: 2012-08-14
Hi,

I have the following code:

function doRemember()
{
  var htmlCode = iView.document.body.innerHTML;
  alert(htmlCode); // Data are being displayed OK!
  Session("htmlCode") = htmlCode;
  alert(Session("htmlCode")); // Does not seem to work!
}

Session("htmlCode") does not get changed... What is wrong? How can I store some value in Session object?

Thanks in advance!
0
Comment
Question by:long8
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 23

Expert Comment

by:b1xml2
ID: 7020749
you cannot update, delete or add Session variables from client-side script. This is so because the script executes only on the client and the server has no knowledge of the changes.
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7020750
what you can do is pass the data back to the server so that it will be changed e.g. via the XMLHTTP Object
or write the changes to cookie on the client side and have your ASP Code read it e.g. Request.Cookies("user")("id")
0
 

Author Comment

by:long8
ID: 7020765
Ah, OK, but could you please tell me how can I pass data from client side to server? Cookies are not acceptable, because they can be turned off in browser.

Is submitting data to database only method?

I'm not very familiar with JS and Web programming at all..
Actually what I need is to pass some text (passing data via URL is not good - text may be rather large) entered by user on one page to another. May be you know a better way?

If you advise me, I'll accept your answer :)
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 23

Accepted Solution

by:
b1xml2 earned 200 total points
ID: 7020783
I would presume that you are using IIS and ASP yes? Well, you may not realise it but for Sessions to work, the client browser must have cookies turned on =).

There is an easy way to update Sessions via the XMLHTTP Object but for which is MSIE Centric (IE5+) and the Web Server should have MSXML Installed (It probably has if you have MSIE5+).

client
======
<script language="javascript">
var oHTTP = new ActiveXObject("Microsoft.XMLHTTP");
var oXML = new ActiveXObject("Microsoft.XMLDOM");
oXML.async = false;

function doRemember() {
 var htmlCode = iView.document.body.innerHTML;
 alert(htmlCode); // Data are being displayed OK!
 if (oXML.documentElement) {
  oXML.removeChild(oXML.documentElement);
 }
 oXML.appendChild(oXML.createElement("payload"));
 oXML.documentElement.appendChild(oXML.createCDATASection(htmlCode));
 oHTTP.open("POST","http://myserver.com/updateSession.asp",false);
 oHTTP.send(oXML);
 alert(oHTTP.responseText);
}
</script>

updateSession.asp
=================
<%@language="VBScript"%>
<%
 On Error Resume Next
 Dim oPayload, szValue
 Set oPayload = Server.CreateObject("Microsoft.XMLDOM")
 oPayload.async = False
 oPayload.load Request
 If oPayload.parseError.errorCode <> 0 Then
  'do nothing
 Else
  szValue = oPayload.documentElement.text
  Session("htmlCode") = szValue
 End If
 Set oPayload = Nothing
 Response.Write Session("htmlCode")
%>




0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7020784
This will allow the data to be passed back to the server discretely without needing a normal HTML form post or a complete page refresh.
0
 

Author Comment

by:long8
ID: 7021045
Wow! Thanks! I didn't try it yet - but it looks exactly what I needed. :)
0
 
LVL 23

Expert Comment

by:b1xml2
ID: 7021074
be sure to ask for any further assistance here if you need and if EE notification is dead, just holler at b1xml2@yahoo.com so that I can come here to this thread to answer your question. Thanks for the grade A =)
0
 

Expert Comment

by:vfwong
ID: 7675357
Do anybody know how to write value to session using JSP?
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
close window in firefox 3 37
Pass a js value to an html form 5 42
Need help for active menu class depending of the page 4 29
Jquery syntax 12 29
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question