Saturday, March 24, 2012

Pass variable values from one ASP page to next ASP page and into javascript

Hi:

I'm not sure if this is even possible... I know NOTHING about asp. My shared hosting server is running on .NET Framework Version 1.1

Here is what I HOPE to be able to do:

Page1.asp has a link in it that opens Page2.asp with the following link:

<a href="http://links.10026.com/?link=Page2.asp?ObjectName=12345&OtherName=ABC">Click this link<br />

On Page2.asp I need to insert the values from ObjectName and OtherName into a javascript section of the page that sends the values into FlashVars parameters:

<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0','width','720','height','545','src','FlashFile','quality','high','bgcolor','#FFFFFF','name','FlashFile','allowscriptaccess','always','loop','false','menu','false','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','FlashFile','flashvars','ObjectName=(???)&OtherName=(?)'); //end AC code </script>

First of all, is this even possible? If so, how is it done? If you can help I would greatly appreciate it. You'll have to give me very specific details, including exactly where on the page the various elements should be placed. (Note that when I hard-code the values for those FlashVars into the javascript code it works perfectly. I just need for it to be dynamic based on which values were sent from Page1.asp.)

Thanks in advance!

Capture the querystring values then populate a couple of hidden form elements. Have your javascript code look at the value property of those elements.

Code Behind

Public Sub Page_Load(ByVal sender as Object, ByVal e as EventArgs) Handles Me.Load

Dim ObjectName as String = Request.Querystring("ObjectName")
Dim OtherName as String = Request.Querystring("OtherName")

End Sub

<script type="text/javascript">

var objName = txtObjectName.value
var othName = txtOtherName.value

( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0','width','720','height','545','src','FlashFile','quality','high','bgcolor','#FFFFFF','name','FlashFile','allowscriptaccess','always','loop','false','menu','false','pluginspage','http://www.macromedia.com/go/getflashplayer','movie','FlashFile','flashvars','ObjectName=' + objName + '&OtherName=' + othName); //end AC code

</script>

<HTML>
...
<input type=hidden name=txtObjectName value='<%= ObjectName %>'>
<input type=hidden name=txtOtherName value='<%= OtherName %>'>

...
</HTML>

Hope this helps


Brian, your solution looks really good but I have a couple of questions about it. (You have to realize that you're talking to a REAL novice here!)

Does all of that coding go into page2.asp? Is "Code Behind" part of the script or is that some sort of instructions for me to do? Shall I test it exactly as you've written it?

Sorry for sounding so dumb, but I guess when it comes to scripting I really am!

Thanks so much for taking the time to help me. Once I hear back from you I'll test it out and let you know how it works.

Len


hehe, I understand. We've all been there trust me... but what you can do to avoid "code behinds" is just insert the code on the aspx (html) page itself. You can this code before the HTML code or inside the HEAD tags. Example

<script runat="server">

Sub Page_Load

Dim ObjectName as String = Request.Querystring("ObjectName")
Dim OtherName as String = Request.Querystring("OtherName")

End Sub

</script>

Just adding this to the previous code should do you justice and lead in the right direction.


Brian is assuming you're developing in ASP.NET and using VB.NET as the language for your code-behind files (files like Page1.aspx.vb or Page1.aspx.cs for C#).

You should still be able to accomplish what you want by using hidden fields though, like he says. Disregard the "Page_Load" section of code and then when you declare your hidden fields:

<input type="hidden" id="myHiddenField" runat="server" value="<%=Request.QueryString("myValue")%>" />

Then in your javascript function you would say:

var myValue = document.getElementById("myHiddenField").value;

and then use myValue as you need it.

I'm still kinda new to ASP.NET and I haven't really worked with ASP, but this should work haha, hopefully. Good luck.


I was just about to test out Brian's solution... now I'm really confused Aeson! Can you spell that out a little more clearly for me?

Thanks!


Hi PalmSpringsLen,

One thing need to clarify first. Is it Classic ASP or ASP.NET. I noticed that you have mentioned two kinds of different technology.
1. ASP.NET with .NET Framework Version 1.1, by default, the file extension for ASP.NET is .aspx not .asp.

PalmSpringsLen:


My shared hosting server is running on .NET Framework Version 1.1

2. Classic ASP pages: Page2.asp

PalmSpringsLen:


Page1.asp has a link in it that opens Page2.asp with the following link:

<a href="http://links.10026.com/?link=Page2.asp?ObjectName=12345&OtherName=ABC" mce_href="Page2.asp?ObjectName=12345&OtherName=ABC">Click this link<br />

By default, IIS Server can run Classic ASP, ASP.NET side-by-side. Please verify which version is exactly used by your web application. You can simply find it out by the file extension.


PalmSpringsLen:

I was just about to test out Brian's solution... now I'm really confused Aeson! Can you spell that out a little more clearly for me?

Thanks!

Sorry to have confused you, but just to make sure we're all on the same page (har har), can you tell us what you're working with?

And sorry for the bad pun.


Hi Aeson;

I was finally able to get the coding to work over the weekend which (for me) was no small feat!

I'm working on a Canadian government project to deliver dynamic web displays of artifacts from a museum. It's a fascinating and revolutionary approach to how objects are displayed in a 3 dimensional fashion. It's going very well so far.

Thanks to you and all who took the time to provide guidance.

Len


I can see where it says "mark as answer", but I can't see "unmark a answer". Where is that?

Thanks


You can click "Mark as answer" on any post(s) that helped you, and if you mark one as an answer the button will change to "Mark as not answer."

Glad to hear you got it working, good luck with the rest of the project.


I tried "mark as an answer" on one of them, but the button did not change to "Mark as not an answer"


Thats strange, when you click "Mark as answer" it should change to "..." and then after it finishes loading it should change to "Mark as not answer." Maybe it's because you've already marked the thread as resolved? I don't really know I'm afraid.

0 comments:

Post a Comment