Solved

How to write value to Session object

Posted on 2002-05-19
8
268 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now