Printing Pages/Page Break

I have an ASP web site that acts as a time tracking program used in billing clients.  On the report page, a user picks various criteria and generates a report.  The problem now is, I need the reports to be one client per page (they need to be printed).  Is there any way in Classic ASP to force a printing page break?
LVL 98
Lee W, MVPTechnology and Business Process AdvisorAsked:
Who is Participating?
This is best done in using CSS. Add the following style to the element you are presenting your records in:

 page-break-before: always;

Example: you are gettíng the data for your report using a recordset. Then you loop thru the data and outputs the name of the client as headline (<h1>) and the info as a paragraph (<p>):

do until myRecordset.eof
 response.write "<h1 style='page-break-before: always;'>" & myRecordset("clientName") & "</h1>"
 response.write "<p>" & myRecordset("clientData") & "</p>"

Ok? More info here:
Lee W, MVPTechnology and Business Process AdvisorAuthor Commented:
Sounds good - I expect to be onsite tomorrow, Thursday at the latest, and will try to implement this - if it works (and no one provides something better - which frankly, this looks pretty simple to me) - the points are yours.
No problem. Just let me know if you need any further advice. Remember to use your browsers preview function to see how your page would look like if you were to print it.
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

page-break-after: always;

is also another method.  I use it on a datagrid that I need to be able to print.  I do an if then statement to put it in after x number of records
Lee W, MVPTechnology and Business Process AdvisorAuthor Commented:
Awesome - gives me a whole new respect for ASP and web based apps (I know, it's CSS, but don't burst my happy bubble).

Points to JohnModig - sorry kevp75, I appreciate the post, but ultimately, the same info you gave was available (blatently) in the link JohnModig posted.
whatever floats your boat.

i use after, because it sets the age break after what is displayed.....before will put the page break before the display......that w3schools site is an awesome resource
Lee W, MVPTechnology and Business Process AdvisorAuthor Commented:
Yes, I am getting a blank page before the reports print, but I'd expect using After would do likewise only AFTER the last page prints.  So ultimately, it seems it wouldn't matter.
it would matter actually....say you are using a table and you want each page to be only 15 rows.  you would use it on the 15th row, so the break would be after the least that's how it's supposed to work, and seems to do the trick when i've used it like that.

I simply did

if recCount = 15 then
  pgBreak = " style='page-break-after:always;'"
end if

and on my rows

the only real problem with breaking on a row is you run a risk of messing up the table in the printed page, so what I would normally do is make a table with 1 row, then start my loop, have another table inside that that contains the data  (so esentially each recordset is it's own table)  and then in my <table> (on the inside of the row)  I put the <%=pgBreak%>

so something like this

'open recordset
response.write "<table><tr><td>"
'start the loop
response.write "<table"&pgBreak&"><tr><td>"&rs("field")&"</td></tr>"  'making each row it's own table, thus making the end of the 15th table the page break
'do the loop
response.write "</td></tr></table>"   'to close out the original row

what I see happening with page-break-before is the page break will be before the tag you inserted the style in
Lee W, MVPTechnology and Business Process AdvisorAuthor Commented:
I ended up using <div> - If a report is selected that needs to cycle through itself with different criteria each time, I use <div class="pagebreak"> but if it's not using a cycle at all, I just use <div>, in both cases, closing with </div>

I admit - if it isn't obvious - CSS is NOT an area of expertise for me.
wasn't for me either, but I'm getting there.

and of course, just as CSS3 comes out too
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.