Author |
Topic |
|
Lycaster
New Member
USA
60 Posts |
Posted - 20 March 2002 : 17:29:05
|
Hello Everyone!
I am trying to build paging into my asp page. Everything works fine except when I try to go past the 3rd page. You see I am using the Server Variable QUERY_STRING for my next and back links. Here is the code:
Dim sQString sQString = Request.ServerVariables ("QUERY_STRING")
' Display PREV page link, if appropriate If Not sCurrentPage = 1 Then Response.Write "<a href='page.asp?" & sQString & "&page=" & sCurrentPage - 1 & "'><IMG src=""images/media/results_back.gif"" border=0></a>" Else Response.Write "<IMG src=""images/media/results_back.gif"">" End If
' Display NEXT page link, if appropriate If Not sCurrentPage = TotalPages Then Response.Write "<a href='page.asp?" & sQString & "&page=" & sCurrentPage + 1 & "'><IMG src=""images/media/results_next.gif"" border=0></a>" Else Response.Write "<IMG src=""images/media/results_next.gif"">" End If
The problem is that when I go past the 3rd page, my asp adds another "page=" after the first one.
So when you are on page 2 the query string would look like this:
page.asp?Section=Media&Sub=Results&ID=578987542&page=2
The second I try to go to page 3 the string does this:
page.asp?Section=Media&Sub=Results&ID=578987542&page=2&page=3
This throws off the page and gives me this error:
Microsoft VBScript runtime (0x800A000D) Type mismatch: 'CInt' /Extranet/Dyna/Modules/media/2.asp, line 104
Here is line 104: sCurrentPage = CInt(Request.QueryString("page"))
Can anyone help out?
Thanks!!!
Jared Wuliger jared@oxcyon.com www.oxcyon.com |
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 20 March 2002 : 17:43:57
|
That happens because you are adding the entire QueryString variable content after "page.asp?".
A question: do the other variables in the query string always occur (Section, Sub, ID)? Are there any more variables that can occur here?
If not I would just do get their individual values and attach them again to "page.asp?" in both lines. That would remove the previous value of the variable page from the new querystring and that would solve your problem.
Was this clear?
------------------------------------------------- Installation Guide | Do's and Dont's | MODs |
|
|
Lycaster
New Member
USA
60 Posts |
Posted - 20 March 2002 : 17:50:22
|
Yes, the string is always different. or I would build out a string like: Sub=" & Request("Sub") & " Or Sub=" & rs("SubCat") & "
So if my string is always dynamic, I dont know what else to use other then Server Variables...
Jared Wuliger jared@oxcyon.com www.oxcyon.com |
|
|
Nikkol
Forum Moderator
USA
6907 Posts |
Posted - 20 March 2002 : 17:51:24
|
The reason you are getting the error is because for page 3 Request.Querystring("page") is equal to "2,3". (Do a response.write to check that out.)
Now, why are you using the servervariable? Why not just use request.querystring? Also, how are sCurrentPage and TotalPages set? Can you take sQString out of the a tag and just do something like:
sSect = Request.QueryString("Section") sSub = Request.QueryString("Sub") sID = Request.QueryString("ID") sCurrentPage = CInt(Request.QueryString("page")) ' Display PREV page link, if appropriate If Not sCurrentPage = 1 Then Response.Write "<a href='page.asp?Section=" & sSect & "&Sub=" & sSub & "&ID=" & sID & "&page=" & sCurrentPage - 1 & "'><IMG src=""images/media/results_back.gif"" border=0></a>" Else Response.Write "<IMG src=""images/media/results_back.gif"">" End If ' Display NEXT page link, if appropriate If Not sCurrentPage = TotalPages Then Response.Write "<a href='page.asp?Section=" & sSect & "&Sub=" & sSub & "&ID=" & sID & "&page=" & sCurrentPage + 1 & "'><IMG src=""images/media/results_next.gif"" border=0></a>" Else Response.Write "<IMG src=""images/media/results_next.gif"">" End If
I hope I didn't make any typos!
Nikkol |
|
|
Nikkol
Forum Moderator
USA
6907 Posts |
Posted - 20 March 2002 : 17:53:16
|
LOL. Oh well, forget my last post then.
Nikkol |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 20 March 2002 : 18:00:52
|
quote:
Yes, the string is always different. or I would build out a string like: Sub=" & Request("Sub") & " Or Sub=" & rs("SubCat") & "
So if my string is always dynamic, I dont know what else to use other then Server Variables...
Ok, my suggestion is to get the whole string, and then use InStrrev to find out whether there is a "&page=" at the end of it and just copy the first part of the string without the page at the end. Try something like this:
sQString = Left (Request.ServerVariables ("QUERY_STRING"), InStrRev(Request.ServerVariables("QUERY_STRING"),"&page=")
I guess this should do it...
Try it and let me know.
------------------------------------------------- Installation Guide | Do's and Dont's | MODs |
|
|
Nikkol
Forum Moderator
USA
6907 Posts |
Posted - 20 March 2002 : 18:00:58
|
Will page always be at the end of the QueryString? Or at the front? You "clip" the querystring to eliminate page=#.
Nikkol |
|
|
Nikkol
Forum Moderator
USA
6907 Posts |
Posted - 20 March 2002 : 18:02:08
|
Dammit Rui...6 secs.
Nikkol |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 20 March 2002 : 18:02:44
|
quote:
Will page always be at the end of the QueryString? Or at the front? You "clip" the querystring to eliminate page=#.
Nikkol
I guess it will always be at the end, given the way he is adding it - always after what comes before. Thus my proposal...
------------------------------------------------- Installation Guide | Do's and Dont's | MODs |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 20 March 2002 : 18:04:03
|
quote:
Dammit Rui...6 secs.
Nikkol
Yeah Nikkol, you gotta be fast on this business ...
------------------------------------------------- Installation Guide | Do's and Dont's | MODs |
|
|
Nikkol
Forum Moderator
USA
6907 Posts |
Posted - 20 March 2002 : 18:09:41
|
Shouldn't it be
sQString = Left (Request.ServerVariables ("QUERY_STRING"), InStrRev(Request.ServerVariables("QUERY_STRING"),"&page=")-1)
I think you left off a ) and I also subtracted 1. If the querystring were something like "id=123&page=2" then yours would return "id=123&", yes? It really doesn't matter as long as you know the "&" is there.
Nikkol
Edited by - Nikkol on 20 March 2002 18:10:13 |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
Posted - 20 March 2002 : 18:25:42
|
quote:
Shouldn't it be
sQString = Left (Request.ServerVariables ("QUERY_STRING"), InStrRev(Request.ServerVariables("QUERY_STRING"),"&page=")-1)
I think you left off a ) and I also subtracted 1. If the querystring were something like "id=123&page=2" then yours would return "id=123&", yes? It really doesn't matter as long as you know the "&" is there.
Nikkol
Well you're right on the parenthesis. I forgot it. And I guess you're also right on the -1.
Glad you took a look at it. The & at the end might be troublesome on subsequent calls (id=123&&page=3) and so on. Don't know if it would cause errors but at least it could lead to a long series of &&&& at the end.
You see this is the danger of copy and pasting code. I got it from a page in my site and I was convinced the count was right, but your correction is meaningful. I should have taken a closer look...
------------------------------------------------- Installation Guide | Do's and Dont's | MODs
Edited by - ruirib on 20 March 2002 18:27:13 |
|
|
Lycaster
New Member
USA
60 Posts |
Posted - 21 March 2002 : 09:37:12
|
Thanks so much to the both of you. I don't know what I would do without people like you!! Rock on!!
Jared Wuliger jared@oxcyon.com www.oxcyon.com |
|
|
ruirib
Snitz Forums Admin
Portugal
26364 Posts |
|
|
Topic |
|