Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Microsoft: ASP (Active Server Pages) FAQ

ASP 101

How can I update the server and reload a page preserving QueryString data? by dbMark
Posted: 24 Aug 04 (Edited 6 Apr 16)

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.


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">
  <TITLE>Test: update server and return to QueryString page</TITLE>
   <a id="RequestLink_1" href="<%=request.ServerVariables("URL")%>?serversidevar="1"<%=CurQString%>">Click here to change something on the server side</a></TD>

Back to Microsoft: ASP (Active Server Pages) FAQ Index
Back to Microsoft: ASP (Active Server Pages) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close