Question Storing Passed Data!!

atr232000

Member
Joined
Jan 9, 2010
Messages
17
Programming Experience
Beginner
Hello Guys and Gals

I hope you can help me.

I am trying to create a bounce.asp page. When the user goes to this site page i want to pass it some data like below

www.testingasp.com/bounce.asp?id=12345?sub=testingme

My goal is to store the "12345" and the "testingme" in a database (The database bit I can do)

on the page load event for bounce.asp i need to store the id= and the sub= values?

How the heck do I do this?? I have looked a sessions and previouspage handlers but I cant get it to work on multiple values!!!

Any help would be great

Thanks

Alan
 

atr232000

Member
Joined
Jan 9, 2010
Messages
17
Programming Experience
Beginner
hello

I added the bit of code to my load page event but it gives we the id=12345?sub=testingme all in one string!

So do I have to do a .split(?) or can you please help with loop as it does not seem to be splitting the keys and values

Dim loop1, loop2 As Integer
Dim arr1(), arr2() As String
Dim coll As NameValueCollection

' Load Form variables into NameValueCollection variable.
coll = Request.QueryString
' Get names of all keys into a string array.
arr1 = coll.AllKeys
For loop1 = 0 To arr1.GetUpperBound(0)
MsgBox("Key: " & Server.HtmlEncode(arr1(loop1)))
' Get all values under this key.
arr2 = coll.GetValues(loop1)
For loop2 = 0 To arr2.GetUpperBound(0)
MsgBox("Value " & CStr(loop2) & ": " & Server.HtmlEncode(arr2(loop2)))
Next loop2
Next loop1
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,728
Location
Sydney, Australia
Programming Experience
10+
You only ever use one ? between the base URL and the query string. If you want to pass multiple parameters in the query string then you separate them using + symbols:
VB.NET:
ht[B][/B]tp://www.testingasp.com/bounce.asp[B][COLOR="#FF0000"]?[/COLOR][/B]id=12345[B][COLOR="#FF0000"]+[/COLOR][/B]sub=testingme
 

atr232000

Member
Joined
Jan 9, 2010
Messages
17
Programming Experience
Beginner
oh right, for some reason then as i add this to the end of my page the

ans.aspx?id=12345+sub=Testingsubject

I get a messagebox
key = id
value=12345 sub=Testingsubject (Notice the "+") is missing from the added sub varaible
 

zoller

Member
Joined
May 12, 2012
Messages
9
Location
New Zealand
Programming Experience
1-3
Ok i'm assuming that a browser has just navigated to http://www.somesite.com/bounce.aspx?name1=aaaa&name2=bbbb

In code behind..

VB.NET:
Dim name1 as String = Request.QueryString("name1")
Dim name2 as String = Request.QueryString("name2")

'name1 = aaaa
'name2 = bbbb

or if you have to get name/values dynamically then isn't this easier?

VB.NET:
For Each nameValue As String in Request.QueryString.Split("&")
Dim name As String = nameValue.Split("=")(0)
Dim value as String = nameValue.Split("=")(1)
Next
 
Last edited:

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,728
Location
Sydney, Australia
Programming Experience
10+
Ah b*gger! Complete brain freeze on my part. A + is supposed to be used in place of a space and it's a & that separates query parameters, as zoller has shown.

The thing is, the QueryString property is type NameValueCollection, as the documentation I linked to shows. It's not a String, so it has no Split method. It's like a Dictionary or Hashtable, except that each key can represent multiple values. As the documentation shows, you can loop through the Keys and use each one to get its corresponding value(s). If there is more than one value then they will be contained in a comma separated String, which you could then split to get the individual values.
 
Top Bottom