Solved

Need to Convert JavaScript Session Variable to VB Classic ASP

Posted on 2010-09-17
6
476 Views
Last Modified: 2012-05-10
I need a way to modify the code below so that I can set it via VB with Classic asp. Currently it works with java Script, however users with Java Script Turned off loose the functionality. If I change it to VB and Server Side it should work for those users.

<script type="text/javascript">document.cookie='userLanguage=<%=Session("userLanguage")%>'</script>
0
Comment
Question by:DakotaKat
[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
  • 3
  • 3
6 Comments
 
LVL 3

Expert Comment

by:FreakyEddie
ID: 33701612
You're allready doing so by using Session("userLanguage")

You set it with
Session("userLanguage") = 1043

and

Retrieve it with
strUserLanguage = Session("userLanguage")
0
 

Author Comment

by:DakotaKat
ID: 33701648
Is there a way I can write the cookie then with out using JavaScript?
0
 
LVL 3

Expert Comment

by:FreakyEddie
ID: 33701675
To write the cookie type in your webpage-code:

Session("userLanguage") = 1043 'for USA

Else please post a bit more code or explain a bit more in how you're using it.
0
Independent Software Vendors: 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!

 

Author Comment

by:DakotaKat
ID: 33701722
I have a language selector that works for everyone with Javascript enabled, but for those who have it turned off they can not write the cookie that is read each time a page it loaded to determine the correct language. Below is the code on the current page.

<% If (Instr(Session("pageLanguages"), "US") > 0) Then %>
            <a title="ENGLISH" style="text-decoration:none" href="<%=Request.ServerVariables("SCRIPT_NAME") & nQueryString%>lang=us">
            <img src="images/flags/en.png" alt="ENGLISH">&nbsp;English</a>
            <script type="text/javascript">document.cookie='userLanguage=<%=Session("userLanguage")%>'</script>

I would like to be able to set that document.cookie value using something serverside if possible. I know it will not solve my problem if they have cookies turned off.
0
 
LVL 3

Accepted Solution

by:
FreakyEddie earned 250 total points
ID: 33701835
To set it:
Response.Cookies("userLanguage")=strSetUserLanguage

To retrieve it:
strRetrieveUserLanguage = Request.Cookies("userLanguage")


You can use the cookies when you want it to be stored for a longer time. When you just want the lifetime of a browser-session, you can use sessions.
0
 

Author Comment

by:DakotaKat
ID: 33701913
Thanks so much FreakyEddie
0

Featured Post

Industry Leaders: 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

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 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