Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to write value to Session object

Posted on 2002-05-19
8
Medium Priority
?
274 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 23

Accepted Solution

by:
b1xml2 earned 800 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

688 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