Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Calling ASP session Variables in JavaScript
Old 01-29-2007, 03:30 PM Calling ASP session Variables in JavaScript
Super Talker

Posts: 116
Trades: 0
I have an interesting question.

I'm writing a web app in ASP (before we convert to ASP.NET).

I'm creating a session variable from one of my functions. I'd like to use this same session variable in a JavaScript function.

Could I call a session variable created in ASP in a JavaScript function?

Here's what I'm doing....

I'm writing a pages HTTP_REFERRER into a session variable URL.

In ASP:
Session("URL")=Request.ServerVariables("HTTP_REFER ER")

I'm programming a JavaScript function that would alter a "#" hyperlink on a page to point to the Session("URL").

Can I call the Session("URL") in JavaScript?

Donna
DonnaZ is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-30-2007, 02:28 AM Re: Calling ASP session Variables in JavaScript
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
Not directly ... but a hidden field is all the magic you need.

It's not just that javascript and asp are different languages; they run on different machines. So you can't just call a variable from one in the other. In .NET you'd serialize a class with the session variables to xml and do all kinds of fancy things. It's the same technique, only less complicated.

hiddenField1.Value = Session("URL");

and then

x = document.getElementById("hiddenField1").innerHtml

Actually I don't know exactly how it'd look on the javascript side ... something basically like that. I really need to learn a lot more js.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 01-31-2007, 01:38 PM Re: Calling ASP session Variables in JavaScript
Super Talker

Posts: 116
Trades: 0
ForrestCroce,

Thanks. But is the example you gave for ASP or ASP.NET?

Also, what if I ran JavaScript from the server?

Donna
DonnaZ is offline
Reply With Quote
View Public Profile
 
Old 01-31-2007, 01:39 PM Re: Calling ASP session Variables in JavaScript
Super Talker

Posts: 116
Trades: 0
What a dope (me, that is)....

I can put this into ASP. But, what about calling JavaScript from the server?

DZ
DonnaZ is offline
Reply With Quote
View Public Profile
 
Old 02-01-2007, 05:49 PM Re: Calling ASP session Variables in JavaScript
ForrestCroce's Avatar
Half Man, Half Amazing

Posts: 3,023
Name: Forrest Croce
Location: Seattle, WA
Trades: 0
I'm not sure I understand; what are you doing with javascript on the server? Normally it's used to program against the brower...
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
ForrestCroce is offline
Reply With Quote
View Public Profile Visit ForrestCroce's homepage!
 
Old 02-02-2007, 05:04 AM Re: Calling ASP session Variables in JavaScript
saadatshah's Avatar
Extreme Talker

Posts: 215
Name: Syed Saadat Ali
Location: Lahore, Pakistan
Trades: 0
use <% Asp Code%> in javascript
__________________
- -- --- ---- ----- ------ ------- ---------------
If you have knowledge, let others light their candles in it.
saadatshah is offline
Reply With Quote
View Public Profile Visit saadatshah's homepage!
 
Old 02-02-2007, 05:15 PM Re: Calling ASP session Variables in JavaScript
Junior Talker

Posts: 2
Trades: 0
Quote:
Originally Posted by saadatshah View Post
use <% Asp Code%> in javascript
I was gunna say just use something like

Code:
<script type="text/javascript">
var test = <% response.write SESSION VARIABLE %>;
that way when the page gets "compiled" on the server it will put the proper asp variable into the JS script for when that is run on the client computer
3n1gm4 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Calling ASP session Variables in JavaScript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.42760 seconds with 12 queries