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.

ASP.NET Forum


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



Reply
I want to use a javascript generated string in a query string.
Old 06-14-2008, 08:55 PM I want to use a javascript generated string in a query string.
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
This is the line of code in the ASP page.

Code:
 
Response.Write("   <tr><a href='Panel.asp?STRING;'><center>"&vbcrlf)
PassStr is the string variable I wish to insert in place of STRING.

PassStr is a javascript variable generated by the client page.

I can't seem to get the syntax right, can anyone help me out?

Sleeping Troll is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-14-2008, 10:07 PM Re: I want to use a javascript generated string in a query string.
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
If it's a javascript variable generated on the SAME page, you can't do it, it's impossible.

Because javascript doesn't execute until the page gets to the client's browser (it's clientside code). At that point the server-side code (ASP) has already finished executing.

Maybe there's a way that you can duplicate how the javascript generates that string, and generate it server-side in the ASP part as well?
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-14-2008, 10:16 PM Re: I want to use a javascript generated string in a query string.
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
The resultant line of code on the generated page would be:

<tr><a href='Panel.asp?STRING;'><center>

I need the syntax to use a variable (PassStr) after the ? ,perhaps I should ask this question in HTML?
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 06-14-2008, 10:25 PM Re: I want to use a javascript generated string in a query string.
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
I just need to insert a reference to the variable in the href before I send the page. I will not be referencing the var server side it will be referenced from html clientside The page Init() function will create the variable.
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 06-14-2008, 10:42 PM Re: I want to use a javascript generated string in a query string.
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
K then instead of ASP, use JS to print it:

Code:
<script type="text/javascript">
document.write('<tr><a href="Panel.asp?'+PassStr+'"><center>');
</script>
__________________
~nyef

Please login or register to view this content. Registration is FREE

Last edited by nyef; 06-14-2008 at 10:46 PM..
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-14-2008, 11:05 PM Re: I want to use a javascript generated string in a query string.
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Sorry, your not getting it, it is tough to explain this is a line of code I have tried that does not work, it is the server side code.

Response.Write("<tr><a href='Panel.asp?"&javascript:Qstring()&"'><center> "&vbcrlf)

my hope was that the link would call a script to return the variable value. Sorry this is so tough to explain, you have been very helpful in past.
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 06-14-2008, 11:12 PM Re: I want to use a javascript generated string in a query string.
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
I want the client side code to be something like:

<tr><a href='Panel.asp?(PassStr)'><center>

If PassStr="abc=xyz&rst=uvw" I want the line to evaluate to:

<tr><a href="Panel.asp?abc=xyz&rst=uvw"><center>
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 06-14-2008, 11:52 PM Re: I want to use a javascript generated string in a query string.
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
And I'm saying, you can't access a javascript variable from server-side code, because the javascript environment DOES NOT EXIST until AFTER the server-side code has finished executing.

If the variable you're talking about (PassStr) is generated by javascript (clientside), you can't access it serverside. If it's generated by JSCRIPT (not javascript) on server-side (by using RUNAT=SERVER), then you'd access it just like you would a vbscript variable:

Response.Write("<tr><a href='Panel.asp?"&PassStr&"'><center> "&vbcrlf)

But if I understand you correctly, the variable PassStr is created by clientside javascript, then you can't response.write it because the variable doesn't exist until after the page leaves the server.

You can, however, add a link to the document from the javascript environment, AFTER the page has loaded. You do not need server-side code for this, you need the javascript code I gave you. Or if you don't want to write it out directly with document.write(), you can modify the contents of an existing div by using document.getElementById('thedivsidgoeshere').inner HTML='whatever html you want to put into the div goes here'.
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-14-2008, 11:58 PM Re: I want to use a javascript generated string in a query string.
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
Basically the order of execution goes:

1. Client requests document from server
2. Server reads document, and parses/runs any server-side code (ASP code occurs)
3. Server now has HTML document generated by server-side code, no more ASP can be executed
4. Server sends HTML documents (which contains javascript) to Client
5. CLIENT (not server) reads document, and parses/runs and client-side code (javascript occurs here).
6. Client displays final document, javascript continues to run after page is displayed.

If the variable PassStr is truly a javascript variable as you said, that variable does not exist until step 5. At that point the page has already been sent to the visitors browser when the javascript starts running. The visitors computer does not have the ability to do a response.write (ASP code) because it is not a web server.

All ASP code (include the response.write you are wanting to create) is executed during step 2. At that point, the javascript environment does not exist. No javascript variables are accessible (although server-side JSCRIPT variables are). There is no way to access the javascript variable "PassStr" because that variable does not exist yet.

ASP and Javascript do not execute simultaneously. Server-side code occurs first, then client-side code occurs. Once client-side code starts running, it is ON THE CLIENT, so all server-side code has already been processed. The client's browser wouldn't know what to do with a Response.Write statement.
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-15-2008, 01:04 AM Re: I want to use a javascript generated string in a query string.
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
I don't want to access the variable server side I just want to put the variable name in the href string so that it can be resolved client side. I want the syntax for using a variable in the href string. I want the page that is sent to contain the variable "name" not the value. when the page is executed at client side it will resolve the variable when the link is clicked. the variable will be given a value onload by clientside script. notice that half the string "panel.asp?" is a literal in string I need to concantate the variable name to this string so that client side it will be recognised as a variable and not a literal.

Last edited by Sleeping Troll; 06-15-2008 at 01:14 AM..
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 06-15-2008, 03:00 AM Re: I want to use a javascript generated string in a query string.
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
Use the javascript code I gave you to write out the <a> tag including the variable.
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-15-2008, 05:08 AM Re: I want to use a javascript generated string in a query string.
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,519
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
Originally Posted by Sleeping Troll View Post
I don't want to access the variable server side I just want to put the variable name in the href string so that it can be resolved client side. I want the syntax for using a variable in the href string. I want the page that is sent to contain the variable "name" not the value. when the page is executed at client side it will resolve the variable when the link is clicked. the variable will be given a value onload by clientside script. notice that half the string "panel.asp?" is a literal in string I need to concantate the variable name to this string so that client side it will be recognised as a variable and not a literal.
I'm not sure I get what you are trying to achieve but as a educated guess it sounds like you want to send a placeholder to the client, then have the client replace the placeholder with the actual values.

so based on that premise


Code:
<%
with response
    .write "<tr><a href="
    .write chr(34)
    .write "Panel.asp?"
    .write "[PLACEHOLDER]"
    .write chr(34)
    .write "><center>"
    .write vbcrlf
end with
%>
Then you can write some client side code to extract the <a>nchor elements from the document and replace the [PLACEHOLDER] with whatever value is needed.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 06-15-2008, 08:58 AM Re: I want to use a javascript generated string in a query string.
Sleeping Troll's Avatar
Ultra Talker

Posts: 351
Name: Butch Begy
Trades: 0
Not exactly what I wanted but it will do, Thx Chris, you too nyef! **** and here I was thinking that a variable was a placeholder!
Sleeping Troll is offline
Reply With Quote
View Public Profile
 
Old 06-15-2008, 12:26 PM Re: I want to use a javascript generated string in a query string.
nyef's Avatar
Ultra Talker

Posts: 265
Name: Lucas
Trades: 0
Sorry I couldn't help you more; I'm still not sure why you're intent on doing it that way.

It seems silly (IMO) to have the server write out something that isn't complete, then have the client code (javascript) complete it. Why not just have the server leave it blank, and have the client generate the whole thing including the link?
__________________
~nyef

Please login or register to view this content. Registration is FREE
nyef is offline
Reply With Quote
View Public Profile Visit nyef's homepage!
 
Old 06-18-2008, 09:05 PM Re: I want to use a javascript generated string in a query string.
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
Quote:
Originally Posted by Sleeping Troll View Post
Not exactly what I wanted but it will do, Thx Chris, you too nyef! **** and here I was thinking that a variable was a placeholder!
A variable is a very specific type of placeholder, and not the type you want or need. A variable is a slot in a computer's memory that can hold values, letting them be manipulated and swapped out as you need. That's kind of what you want to do, only instead of in RAM, you want to create the placeholder on your server, and have it manipulated and swapped out on the client. The way programming variables work, as in process memory working areas, the boundaries between two machines makes it impossible to "share" them.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to I want to use a javascript generated string in a query string.
 

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.46787 seconds with 12 queries