Send value from one ASP page to another

Many times it comes necessary to share information between webpages. One of the ways that can be done is by using the querystring method. In the querystring method, the inforamtion is first added to the URL of a web page; then, the inforamtion is requested from the URL. The script below shows you how to use querysting to find out which link the user clicked on. Note that you should avoid sending huge amount of information with the querysting method as the URL will become huge!

Scripting code

First step: add information to the URL of a web page.

' in the page where you want to send the value from, write this code
dim strFileName, strVariableName, strValueToPass, strLinkText
strFileName = "send-value.asp"
strVariableName = "LinkID"
strValueToPass = "10"
strLinkText = "Click here to send the value!"

SendValue strASPFile, strVariableName, strValueToPass
sub SendValue (strASPFile, strVariable, strValue)
dim shtml
shtml = "<a href='" & strASPFile & "?" & strVariableName & "=" _
& strValueToPass & "'>"
shtml = shtml & strLinkText & "</a>"
response.write shtml
end sub

Second step: request the information from the URL

' in the page that will recieve the value, write this code
' Notes: 1) this page must be named to whatever strFileName is set to above.
' 2) use the value of strVariableName to make the querystring request.
' For instance, if strVariableName = "SearchTerm", then,
' request.QueryString("SearchTerm")!
dim strSentValue
strSentValue = request.QueryString("LinkID")
if strSentValue <> "" then
response.write "Value sent to this page is: " & strSentValue
end if

Output of the above code

To see the output of the above code, click on the link below:

Click here to send the value!