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

Creating additional ASP pages dynamically

Status
Not open for further replies.

jisoo22

Programmer
Apr 30, 2001
277
0
0
US
Hello all!

I'm putting together an ASP page that uses VBScript to read in a text file and puts it up on the page. I'm also trying to design it so that if the text is past a certain length, the VBScript will cut off the end, stick it onto a second ASP page and create a link to it on the initial page. Here's the code I've been working on (in skeleton form):


<%
Dim fso, f
Dim text
Dim text1
Dim text2
Dim counter
counter = 1
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set f = fso_OpenTextFile(&quot;c:\inetpub\ 1)
text = f.ReadAll
Session(&quot;text&quot;) = text
Session(&quot;counter&quot;) = counter
If screenWidth => 1024 Then
Do Until Len(text) < 5500
Session(&quot;text&quot; & Session(&quot;counter&quot;)) = Left(Session(&quot;text&quot;), 5500)
Session(&quot;text&quot;) = Mid(Session(&quot;text&quot;), 5501, Len(Session(&quot;text&quot;)))
Response.Write Session(&quot;text&quot; & Session(&quot;counter&quot;))
Session(&quot;counter&quot;) = Session(&quot;counter&quot;) + 1
Loop
Session(&quot;text&quot; & Session(&quot;counter&quot;)) = text
Response.Write Session(&quot;text&quot; & Session(&quot;counter&quot;))
Session(&quot;counter&quot;) = Session(&quot;counter&quot;) + 1
Else
Response.Write Session(&quot;text&quot;)
End If
%>


Can someone tell me how I can do that?

Thanks,
Jisoo22
 
Just in case I forgot to mention, I also need someone to show me how I can get the VBScript to create a new ASP page so the link can point at it.

Thanks,
Jisoo22
 
You don't need to &quot;create&quot; a second page. Just build the functionality into the ASP page. Have the ASP page take a parameter, let's use
Code:
pageNumber
. Then specify the number of characters to display for each page in a variable in the ASP page, let's call the variable
Code:
pageSize
. So now by using these two numbers you can determine dynamically what part of the file is displayed. The Lower bound of the page can be (pageNumber - 1) and the Upper bound can be just pageNumber.

Example:
Code:
pageNumber = 2
pageSize = 500 characters
lowerBound = 500
upperBound = 1000

Now you can parse the file for the specified characters and determine if you need to add a link for the next page. Also you could determine how many total pages. Just make sure you add adequate error checking.

Sorry if my explanation was a bit confusing. This right off the top of my head, there may be a much better way of doing it. Anyone else want to try?

Oh BTW, this is going to be very processor intensive and not very scalable because you are guarunteed to use alot of disk I/O. It would be a better solution to store these documents in a database. Wushutwist
 
Ok so I think I might understand the idea of building the functionality into the page, but I'm pretty new to ASP so could you give me a little quickie example of how to do this?

Thanks,
Jisoo22
 
thispage.asp
<%
const pagesize = 500 'in characters

if request(&quot;pageID&quot;) = &quot;&quot; then
pageID = 1
'if they just got here, assume page 1
else
pageID = cint(Request(&quot;pageID&quot;))
'otherwise read pageID from the querystring
end if
'now write out the text that falls on that page
response.write mid(text,((PageID-1)*PageSize)+1, PageID*PageSize)
%>

<p>
<a href=&quot;thispage.asp?pageID=<%=PageID + 1%>&quot;>Go to page <%=PageID + 1%>.</a>

oh and btw... get rid of those session variables, they'll kill you in the end if the overhead of all the disk i/o doesn't first.

Eddy Dumire
eddy.dumire@knowledgecg.com
 
Also you are going to have to put a little bit more intelligence in it to make the pages readable. You wouldn't want the ASP page to cut off in the middle of a word. So you will have to read until the next blank space if the last character read is not a space. Also in the beginning of the page you will need use the same technique so that you don't repeat the last word written by the previous page (unless of course it is page 1).

First get the thing working the first way then worry about adding this sort of stuff. Wushutwist
 
Ok, so I see how everything works but what about parameters? Someone told me that when you use the parameters, you get a URL that looks something like: &quot; Can someone show me how to use this? Does it involve the querystring method?

Thanks,
Jisoo22
 
Hello again!

I'm still having some trouble trying to implement this, can anyone tell me what I'm doing wrong? Here's what I have so far:


<%
Dim fso, f
Dim text
Dim text1
Dim text2
Dim counter
Dim pageID
Dim pageSize
pageSize = 500
counter = 1
Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set f = fso_OpenTextFile(&quot;c:\inetpub\ 1)
text = f.ReadAll
Session(&quot;text&quot;) = text
Session(&quot;counter&quot;) = counter

If request(&quot;pageID&quot;) = &quot;&quot; Then
pageID = 1
Else
pageID = cint(Request(&quot;pageID&quot;))
End IF

If screenWidth => 1024 Then
Do Until Len(Session(&quot;text&quot;)) =< 5500
Session(&quot;text&quot; & Session(&quot;counter&quot;)) = Left(Session(&quot;text&quot;), 5500)
Session(&quot;text&quot;) = Mid(Session(&quot;text&quot;), 5501, Len(Session(&quot;text&quot;)))
Response.Write mid(Session(text),((pageID-1)*pageSize)+1, pageID*pageSize)
Response.Write &quot;End of page &quot; & Session(&quot;counter&quot;)

Session(&quot;counter&quot;) = Session(&quot;counter&quot;) + 1
Response.Write &quot;<a href=&quot;&quot;thispage.asp?pageID=&quot;&quot;&quot;&quot; & <%=PageID + 1%> & &quot;&quot;>Go to page&quot; & <%=PageID + 1%> & &quot;</a>&quot;
Loop
Session(&quot;text&quot; & Session(&quot;counter&quot;)) = Session(&quot;text&quot;)
Response.Write Session(&quot;text&quot; & Session(&quot;counter&quot;))
Session(&quot;counter&quot;) = Session(&quot;counter&quot;) + 1
Else
Response.Write Session(&quot;text&quot;)
End If
%>


I think I also have a problem with the first &quot;response.write&quot; method, there's not enough quotation marks somewhere but not sure where.

Thanks,
Jisoo22
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top