Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

passing paramaters to asp pages 1

Status
Not open for further replies.

harpconn

Technical User
Jul 15, 2002
15
0
0
US
I need to pass a textstring and an array from one asp page to another. They are created by program code, not by form input.

I am getting various errors, including "type mismatch" even though I have identical Dim statements in each page.

Here's my test code. Please tell me what I'm doing wrong.

PAGE1
-------
<%@Language=VBscript%>
<%Option Explicit%>

<html>

<head>
<title>TempTest</title>
</head>

<body>
<%
Dim MyList, MyArray(5), I

MyList = &quot;abcde&quot;
For I = 1 to 5
MyArray(i)= I
next
%>
[<a href=&quot; Paramaters</a>]

</body>

</html>
--------------------------------------------------------

PAGE 2
<%@Language=VBscript%>
<%Option Explicit%>

<html>

<head>
<title>TempTest2</title>
</head>

<body>
<%
Dim MyList2, MyArray2(5), I2

MyList2 = request.querystring(&quot;MyList&quot;)
response.write &quot;*** DEBUG: MyList2 = &quot; & MyList2 & &quot;<BR>&quot;

MyArray2 = request.querystring(&quot;MyArray&quot;)

For I2 = 1 to 5
response.write MyArray2(I2) & &quot;<BR>&quot;
next

%>
</body>

</html>
 
I am betting your getting the value &quot;MyList&quot; for your querystring variable MyList2 and the value &quot;MyArray&quot; for the QueryString variable MyArray2

The problem here is that your never actually outputting those ASP variables into the HTML. What you need to do is write the values of those variables into the link. The MyList variable will be easy because you can simply write it out like so:
Code:
mypage.asp?MyList2=<%=MyList%>

The array is a little more difficult because you cannot pass arrays inside the querystring, only strings. The easiest solution would be to use the Join function to Join the array into a delimited astring. Then on the second page you could use the Split function to split the string back into an array:
Code:
Dim arrStr
arrStr = Join(myArray,&quot;,&quot;)    'join together with comma delimiter
%><a href=&quot;myPage.asp?myArray=<%=arrStr%>&quot;>My Link</a><%

Then on the next page:
Dim myArray, arrStr
arrStr = Request.QueryString(&quot;myArray&quot;)
myArray = Split(arrStr,&quot;,&quot;)   'split on comma delimiter


Hope this helps,
-Tarwn [sub]01010100 01101001 01100101 01110010 01101110 01101111 01101011 00101110 01100011 01101111 01101101 [/sub]
[sup]29 3K 10 3D 3L 3J 3K 10 32 35 10 3E 39 33 35 10 3K 3F 10 38 31 3M 35 10 36 3I 35 35 10 3K 39 3D 35 10 1Q 19[/sup]
Get better results for your questions: faq333-2924
Frequently Asked ASP Questions: faq333-3048
 
That took me a long way. Thanks. Both the strings are getting across OK. But I'm still getting a &quot;type mismatch&quot; error on the second pages split line 19. So I don't end up with an array on page 2.

I don't understand why. Here's the revised code:

PAGE1
---------------
<%@Language=VBscript%>
<%Option Explicit%>

<html>

<head>
<title>TempTest</title>
</head>

<body>
<%
Dim MyList, MyArray(5), arrString, I

MyList = &quot;abcde&quot;

For I = 0 to 4
MyArray(I)= I
next

arrString=Join(MyArray,&quot;,&quot;)

%>

[<a href=&quot; Parameters</a>]

</body>

</html>
----------------------
PAGE 2
<%@Language=VBscript%>
<%Option Explicit%>

<html>

<head>
<title>TempTest2</title>
</head>

<body>
<%
Dim MyList2, MyArray2(5), arrString2, I2

MyList2 = request.querystring(&quot;MyList2&quot;)
response.write &quot;*** DEBUG14: MyList2 = &quot; & MyList2 & &quot;<BR>&quot;

arrString2 = request.querystring(&quot;MyArray2&quot;)
response.write &quot;*** DEBUG17: arrString2= &quot; & arrString2 & &quot;<BR>&quot;
MyArray2=Split(arrString2,&quot;,&quot;)

For I2 = 0 to 4
response.write MyArray2(I2) & &quot;<BR>&quot;
next

%>
</body>

</html>


Thanks. You're the greatest!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top