Thursday, January 03, 2008

Pagebreaking on ASP.net

First of all wish you are very happy and healthy new year.

A friend of mine wanted to out put and print some stuff using ASP.net , yah not a problem. But the problem was he wanted to force page breaks between section. Actually he wanted to override default browser behavior of breaking pages while it prints. Hmm can we do this????

YES, we can and I did some research and a small style sheet did the trick. Here is the code.

This code will go between the header tages or you can use an external style sheet

<style type="text/css">

@media Print   
{
    .pagebreak
    {
       PAGE-BREAK-BEFORE: always
    }
}

</style>


Now in your actual html code

<h1> Page 1 </h1>
<p class="pagebreak"></p>
<h1> Page 2 </h1>
<p class="pagebreak"></p>
<h1> Page 3 </h1>


This works fine both on IE7 and FF2

Have Fun
Fiqri

#    Comments [1] |