| Author |
Topic Search Topic Options
|
theSCIENTIST
Senior Member
Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
|
Post Options
Thanks(0)
Quote Reply
Topic: QueryString parameters Posted: 27 June 2005 at 1:01am |
|
Hi folks,
Been scratching my head on this one, and nothing, my problem is this:
We all pass stuff along using the querystring, however, how does one solve the problem of adding another parameter to the existing parameters in the querysting?
Response.Write(vbCrLf & " <a href=""" & thisFile & "?" & Request.ServerVariables("QUERY_STRING") & "&shw=cds"" class='link'>Show all codes</a>")
This works for the first time, a [&shw=cds] is added to whatever is already there, but has I keep pressing the link more and more [&shw=cds] are added.
Any solutions?
|
|
|
 |
dpyers
Senior Member
Joined: 12 May 2003
Status: Offline
Points: 3937
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 June 2005 at 1:49am |
|
Something like...
If Lcase(Request.QueryString("shw")) <> "cds" Then
Add to the QUERY_STRING
Else
Use it as is.
End If
|
Lead me not into temptation... I know the short cut, follow me.
|
 |
theSCIENTIST
Senior Member
Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 June 2005 at 2:46am |
|
Isn't there a more subtle way to do it?
That means all my links will have to have that check.
|
|
|
 |
dpyers
Senior Member
Joined: 12 May 2003
Status: Offline
Points: 3937
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 June 2005 at 10:21am |
|
If you're calling the same page, you might want to clear the request object somewhere in the page.
If you do have multiple entries for a parameter, I think it is
referenceable as an array similar to multiple entried servervariables.
If you don't specify an index value, it gets the first entry.
A query string has a limit of around 1K (for some reason I think it
might be 968 characters). Data and parameter characters count towards
the limit.
If the limit is an issue or if you just want to clean up the look of the url you might want to POST the info via a hidden form.
In .net you can use a url handler to automatically rewrite the url but still retain the request object.
|
Lead me not into temptation... I know the short cut, follow me.
|
 |
theSCIENTIST
Senior Member
Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 June 2005 at 11:21am |
My app is a 1 file app, so I'm not calling and passing queries to other files, even so, I find it too awkward to have to add so much code just to preserve all queries already in the URL and add another query to it. Observe:
Old link:
Response.Write(vbCrLf & " <a href=""" & thisFile & "?" & Request.ServerVariables
("QUERY_STRING") & "&shw=cds"" class='link'>Show all
codes</a>") |
New link:
Response.Write(vbCrLf & " <a href=""" & thisFile & "?" & Request.ServerVariables("QUERY_STRING") & "")
If LCase(Request.QueryString("shw")) <> "cds" Then Response.Write("&shw=cds")
Response.Write(""" class=""link"">Show all codes</a>") |
For the new link I need 3 lines of code just to add a query string and preserve all others already in the URL?
Such a simple operation, isn't there an easier way?
I have hundreds of links in my file, and to change them all, the file will triple in size.
Ideas please.
Edited by theSCIENTIST - 27 June 2005 at 2:00pm
|
|
|
 |
dj air
Senior Member
Joined: 05 April 2002
Location: United Kingdom
Status: Offline
Points: 3627
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 June 2005 at 11:40am |
|
what about
strQuerystring = Request.ServerVariables("QUERY_STRING")
if NOT intstr(1, Lcase(strQuerystring), "shw=cds", vbTextCompare) then
strQuerystring = strQuerystring & "shw=cds"
END IF
you could even add it within a function so its url" & call function()
just an idea not sure any of that is helpful
|
 |
dpyers
Senior Member
Joined: 12 May 2003
Status: Offline
Points: 3937
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 June 2005 at 12:13pm |
|
Perhaps a different approach using session variables to avoid the querystring entirely?
|
Lead me not into temptation... I know the short cut, follow me.
|
 |
theSCIENTIST
Senior Member
Joined: 31 July 2003
Location: United Kingdom
Status: Offline
Points: 440
|
Post Options
Thanks(0)
Quote Reply
Posted: 27 June 2005 at 1:59pm |
|
Great ideas, a function or session vars, however can you post an example of the function & call approach, something so I can use the links as usual like; <a href="" & thisFile & "?" & smartQuery(shw=cds) & ">Codes</a>
Note smartQuery(shw=cds) is the function that would return a URL with all the old queries but also add to them a new shw=cds parameter and also calculate whether to insert it or if it's already ther don't insert it.
Can you give me an example of a function like this?
My app uses a great deal os queries whateverapp.com/project.asp?op=ac&bid=33&nc=0&bp=0&shw=cds so I don't know which approach to use.
I prefer not to use session variables as this project is a one file blog application that will be used by many people have their own blog, so session vars would conflict.
|
|
|
 |