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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I update the server and reload a page preserving QueryString data?

ASP 101

How can I update the server and reload a page preserving QueryString data?

by  dbMark  Posted    (Edited  )
Picture this: Your user is on a page and they want to select something that will force a change in a setting you have on your ASP objects, such as a variable in a COM object or whatever. Ignoring possible methods using cookies or go.back, this is one way it can be updated and put the user back on the page he was at with the QueryString data preserved. (As I said, there surely are other ways, but this one works and demonstrates how to pick up and recycle the QueryString data.)

Typically, GET/QueryString data is used to set up a page while POST/Form data is used for data submission. Since that's not always the case, you have to be sure that re-creating your GETs won't do something unwanted such as duplicating one-time writes or requests, etc.
Code:
<%
Dim xPass, xPassTmp, in_PassItem, curQString
curQString = ""
in_PassItem = "0"
If session("ee_data") <> "" Then
    If Request.ServerVariables("REQUEST_METHOD")="GET" Then
        xPass = False  ' flag for valid changes
        ' check for special server-side update
        xPassTmp = Request.QueryString("serversidevar")
        ' this example will filter for valid entry request, such as a number 1 to 5
        If varType(xPassTmp) = 8 and len(xPassTmp) = 1 Then
            If inStr("12345",xPassTmp) > 0 Then
                session("myObj").aspPassItem = xPassTmp
                xPass = True
            End If
        End If
        If xPass Then
            ' Redirection to this page again is done since a user selecting a page
            ' (not Pass case) might interfere with some pages which call themselves
            ' with and without passing URL variables.
            ' Only GET (QueryString) is resent, not POST (Form).
            If len(request.QueryString("passqs")) > 0 Then
                curQString = "?" & request.QueryString("passqs")
            End If
            response.redirect "https://" & request.ServerVariables("server_name") & request.ServerVariables("URL") & curQString
        End If
    End If
    ' this next code executes only if this is a standard querystring entry
    in_PassItem = session("myObj").aspPassItem
    If len(request.ServerVariables("query_string")) > 0 Then
       curQString = "&passqs=" & server.URLEncode(request.ServerVariables("query_string")) ' in case new setting selected
    End If
End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE>Test: update server and return to QueryString page</TITLE>
 </HEAD>
 <BODY>
   <a id="RequestLink_1" href="<%=request.ServerVariables("URL")%>?serversidevar="1"<%=CurQString%>">Click here to change something on the server side</a></TD>
 </BODY>
</HTML>
dbMark
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top