Important alert: (current site time 7/15/2013 10:16:58 PM EDT)
 

VB icon

A simple paging ASP script

Email
Submitted on: 2/21/2002 7:58:28 AM
By: Antonio Carlos Barbosa  
Level: Beginner
User Rating: By 4 Users
Compatibility: ASP (Active Server Pages)
Views: 33360
author picture
(About the author)
 
     This script is a generic text and article paging routine. It uses a SESSION in order to break down the overhead and increases performance dramatically when you're working with recordsets. Can be used in many purposes. All that you have to do is to put a text with as many tags you want into the variable "cTexto". A sample can be ran at http://www.qbusca.com.br/snip/exemplos/008/paginar.asp
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: A simple paging ASP script
' Description:This script is a generic text and article paging routine. 
It uses a SESSION in order to break down the overhead and increases performance dramatically when you're working with recordsets. Can be used in many purposes. All that you have to do is to put a text with as many <NEWPAGE> tags you want into the variable "cTexto".
A sample can be ran at http://www.qbusca.com.br/snip/exemplos/008/paginar.asp
' By: Antonio Carlos Barbosa
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7249&lngWId=4'for details.'**************************************

<STYLE>
.list-text{
FONT-SIZE: 10px; COLOR: #000000; FONT-FAMILY: Arial, Helvetica, Geneva, Swiss, SunSans-Regular
}
</STYLE>
<%
nPag = REQUEST("nPag")
If nPag = "" Then nPag = 1
If SESSION("cText") = "" Then
 ' -----------------------
 ' Here you can read a database field with the article or put the text you want to page.
 ' It is done just once, due the first time it will be saved into a SESSION variable
 ' -------------------------------------------------
 cTexto = "This is the page 1 <NEWPAGE>" &_
"This is the page 2 <NEWPAGE>" &_
"This is the page 3 <NEWPAGE>" &_
"This is the page 4"
Else
 cTexto = SESSION("cText")
End If
cLinks = ""
nTot = 0
cPagina = ShowByPage(cTexto,nPag,nTot,cLinks)
Response.Write cPagina
Response.Write cLinks
Function ShowByPage( cTxt,nPage,ByRef nTotal, ByRef cLinks )
 Dim nI
 Dim i : i = 1
 Dim cAux : cAux = cTxt
 Dim cPagina : cPagina = ""
 Dim cURL : cURL = Request.ServerVariables("SCRIPT_NAME")
 If nPage = "" Then
 SESSION("cText") = cTxt
 nPage = 1
 End If
 ShowByPage = ""
 cLinks = ""
 nTotal = 1
 nPage = CInt(nPage)
 While i > 0
 i = InStr(1,cAux,"<NEWPAGE>")
If i > 0 Then
 cPagina = Mid(cAux,1,i-1)
 cAux = Mid(cAux,i+9,Len(cAux))
 If nTotal = nPage Then
 ShowByPage = cPagina
 End If
 nTotal = nTotal + 1
End If
 Wend
 cPagina = cAux
 If nTotal = nPage Or ShowByPage = "" Then
 ShowByPage = cPagina
 End If
ShowByPage = "<DIV Class=list-text>" & ShowByPage & "</DIV>"
 If nTotal > 1 Then
For nI = 1 To nTotal
cLinks = cLinks & " <a class='list-text'href='" & cURL & "?nPag=" & nI & "'>" & nI & "</a>"
Next
 End If
 cLinks = "<hr Class=list-text>" & _
 cLinks & "<a Class=list-text> de " &_
 nTotal & "</a>"
End Function
%>


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
2/27/2002 11:01:49 AMJos Keuter

Nice work! 1 Excellent rating by me (simple is beautifull). I would have used the Split-function to get the current page very easily: cPages = Split(cTxt, "") -> ShowPage cPages(n)
(If this comment was disrespectful, please report it.)

 
7/12/2008 2:44:47 PManant

the code are realy good
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.