Hi Daniel,
Kevin - Yes i had looked at repeaters but I have never used them before
and was not sure if they can handle absolutely positioned items, if i
understand right a repeater needs a template given to it, so i woul dhave
to pass in my full structure of my table layout but use the
databinder.eval where the vars would go. Is that right? If you can provide
some sample code on a very basic repeater that would help.
A Repeater will repeat whatever HTML is inside it, and whatever HTML is
rendered by Controls inside it. Looking at the ASP.Net object model, an
ASP.Net Page is an HttpHandler, which is also a Templated Control, and a
container for a WebForm, and/or other .Net Server Controls. Note that it is
also a Control. A Control renders HTML to an HttpHandler's
Response.OutputStream. So, you have 2 diffferent classes of Controls here.
One handles an HTTP Request. Both write HTML to an HttpHandler's
Response.OutputStream. You only need one HTTP Handler to handle a Request.
There is only one Response, and that belongs to the HttpHandler.
Let's take a look at your initial (ASP) solution to your requirements:
So, breaking this down abstractly into a set of requirements, you have a
requirement to create a single HTML document that prints out as multiple
printer documents. You're fetching data from a database and populating an
HTML table with the data.
According to your OP, you're not building more than one page. You're adding
HTML blocks to a single web page, and using CSS page breaks to break it up
when printing, correct?
It is important to note that, while ASP.Net uses a fully-object-oriented and
highly-structured object model, under the hood, ASP and ASP.Net both do the
same thing: They handle HTTP Requests, perform server-side processing, and
render HTML to the Response object's output stream, which is a file stream.
I may be wrong here, but I think I detect a bit of confusion between the
word "page" in the context of a web page rendered by ASP or ASP.Net, and
"page" in the context of printing. It is important to distinguish between
them. A single HTML web page can (and often does) print out to many pages on
a printer. Forgive me if I'm wrong about your understanding regarding this.
Okay, so, how does the web page control where the printer pages break? Well,
there are 2 options: If no CSS page breaks are used, the printer will create
page breaks at points in the page where the remaining content does not fit
in the printed page, whatever its dimensions are. The printer knows the
dimensions of the printable page, and the dimensions of the web page, and
simply cuts it up wherever it happens to break. If CSS page breaks are used,
the printer will break and create a new page whenever it encounters one of
these breaks. Also, if the content between the CSS breaks is longer than the
printable area, the printer will chop this up too. So, if we want full
control over the pagination, we need to ensure that the HTML content between
the page breaks is smaller than the printable page size.
Putting it all together, you want to create a single HTML document from
multiple database records. This single HTML document will repeatedly render
HTML blocks that are smaller than the printable target area, and put CSS
Page breaks between them.
So, note that we haven't talked about having to render more than one ASP.Net
page; only that we need to break it up into repeating blocks, one for each
database record.
This is exactly what a Repeater Control does. It is like an "embedded"
template in a Page. The Repeater Template is databound to data in a data
source, such as a DataSet or DataTable. It will repeat its functional output
once per item in the data source. This could include style information, as
well as CSS Page breaks, in addition to the content of each invoice. Here
are some excellent references regarding Repeaters, using Templated Controls,
and DataBinding Expressions:
http://msdn.microsoft.com/library/d...genref/html/cpconrepeaterwebservercontrol.asp
http://msdn.microsoft.com/library/d...us/dnaspp/html/databoundtemplatedcontrols.asp
http://msdn.microsoft.com/library/d...frlrfsystemwebuidatabinderclassevaltopic1.asp
As for your absolute positioning (thought I'd forgot?), There is no doubt a
CSS solution to your positioning problem. However, using absolute
positioning is not likely to be the solution. It may involve the judicious
use of HTML tables, with perhaps some relative positioning of the tables
themselves. The table can be used to keep everything inside it aligned
relatively within the table, and then use relative positioning to position
itself relative to the printed page (left, right, top, bottom).
BTW, you could also combine the use of a Repeater with a User Control in it,
as Peter suggested. The User Control would contain all the content you want
repeated, and be data-bound to each individual record via data binding. This
may not be necessary, depending upon your overall requirements
(extensibility, for example).
--
HTH,
Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.