June 2002
Intermediate to advanced
816 pages
28h 12m
English
QueryString
NameValueCollection = Request.QueryString
The
QueryString collection returns an
instance of the NameValueCollection class
containing all the keys and values passed as a part of the query
string (typically by submitting an HTML form that uses the GET method
instead of POST).
NameValueCollection
An Object variable of type NameValueCollection.
The example writes the contents of the QueryString collection to the browser:
Sub Page_Load( )
Dim Counter1, Counter2 As Integer
Dim Keys(), subKeys( ) As String
Dim QSColl As NameValueCollection
' Load QS into NameValueCollection
QSColl=Request.QueryString
' Get keys into an array
Keys = QSColl.AllKeys
For Counter1 = 0 To Keys.GetUpperBound(0)
Message.Text &= "Key: " & Keys(Counter1) & "<br/>"
subKeys = QSCol1.GetValues(Counter1) 'Get all values under this key
For Counter2 = 0 To subKeys.GetUpperBound(0)
Message.Text &= "Value " & CStr(Counter2) & ": " & _
subKeys(Counter2) & "<br/>"
Next Counter2
Message.Text &= "<br/>"
Next Counter1
End SubThe following code can be used to post to the example page (note that the form method attribute has been set to GET, which is required for the form value to be sent as part of the query string):
<html>
<head>
<title>Submit a named parameter via POST</title>
</head>
<body>
<form id="form1" action="QueryString.aspx" method="GET">
<h3>Name:</h3>
<input type="text" name="name">
<input type="submit">
</form>
</body>
</html>One advantage that the QueryString collection ...
Read now
Unlock full access