Solved

How to write value to Session object

Posted on 2002-05-19
8
273 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

617 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