Click to See Complete Forum and Search --> : Passing a session variable from vb.net into javascript
SoniaE
May 11th, 2004, 01:46 PM
I am trying to open a new window from within my vb.net code (asp.net web app) but the path is dynamic and only gets set at runtime. Is there a way to do this - Below results in errors as the session variable is not recognized...Any other, better ways ,of accomplishing this?
RegisterStartupScript("Key", "<script language='javascript'>window.open( Session("Path"), 'Reports');</script>")
anupam kant
May 12th, 2004, 10:49 AM
If I am not wrong you have the url stored in Session("Path") variable, and you want to open this url in new window.
If this is the case then simply write following script on aspx page:
<script language='javascript'>
window.open( '<%=Session("Path")%>', 'Reports');
</script>
hope this helps:
SoniaE
May 12th, 2004, 01:57 PM
Hi - thanks for your reply,
When I try to pass in the session variable in that format - I get an error that says:
"Comma,')', or a valid expression continuation expected"
on the Session("Path') - "Path" part (it's get's highlighted as the error source.
(Maybe this will help further explain my difficulties - this javascript is embedded in a sub routine in the vb.net server-side code. It's not client side) Not sure if I made that apparent before.
Any help that you are able to offer is much appreciated - thanks.
anupam kant
May 13th, 2004, 12:16 AM
OK
to embed that script in server side code you just need to write
Response.Write("<script language='javascript'>
window.open( '+ Session("Path") + ', 'Reports');</script>")
in .vb file.
:)
SoniaE
May 13th, 2004, 08:24 AM
Thanks so much!
The syntax actually requires an extra pair of quotes on the session variable:
Response.Write("<script language='javascript'> window.open(' " & Session("File") & " ', 'Reports');</script>")
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.