Newby/Novice Question: Printing Web Pages...

B

Blue Streak

Hello, I have a question for the group.

My current project uses multiple panels to display the contents of a
web page. The thing is many of these panels are hidden while only one
is visible at a time (much like tabs). I use a set of command buttons
to switch between these panels. What I would like to do is to create a
print function that will create a preview showing all panels in
sequential order which could be used to print a hard copy.

Any suggestions?

TIA...
 
A

addup

The simple answer is: Use CSS to do the dirty work

You can set up different stylesheets for screen and print (an example
to follow)

BUT:
It all depends on your app

Is all your data easily available upfront? is there a lot of overhead
involved in fecthing data to be displayed on the other "tab"s

Are your clients on a low latency connection to the server?

EXAMPLE:

<STYLE type="text/css">
@media print { .ScreenOnly { display: none; } }
@media screen { .PrintOnly { display: none; }
.TabContentHidden { display: none; visibility: hidden; } }
</STYLE>

<DIV class="ScreenOnly" >This content will not be printed</DIV>
<DIV class="PrintOnly" >This content will not be visible on screen, but
<B>will</B> be printed</DIV>
<DIV class="TabContentHidden" >This is an invisible panel (but will
print)</DIV><DIV class="TabContent" >This is the visible panel (both
print and screen)</DIV>
<DIV class="TabContentHidden" >This is an invisible panel (but will
print)</DIV>

The other advantage to this approach is that you can switch "tabs" on
the browser without the server roundtrips (read near-instantaneous)

Hope this helps
-- addup --
 
B

Blue Streak

Hmmm.

That looks interesting and might work if I had things setup "normally"
but that approch wouldn't work, I think. I am using ASPdotNET (i.e.
postbacks) to make the different panels/DIVs visible or not. If a
panel is not set as visible by the server it doesn't even show up on
the client side.

Private Sub btnPg1_Click(sender as Object, e as EventArgs) Handles
btnPg1.Click
pnlPg1.Visible = True
pnlPg2.Visible = False
pnlPg3.Visible = False
pnlPg4.Visible = False
pnlPg5.Visible = False
End Sub

Is there perhaps more of a dotNET approach?

TIA...

I guess I should lookup more on that CSS stuff.
 
B

Ben Dewey

You will have to change from ASP.Net Visibility to CSS visiblity:

pnlPg1.Visible = true
pnlPg1.Attributes.Add("display", "");
pnlPg2.Visible = true
pnlPg2.Attributes.Add("display", "none");
pnlPg3.Visible = true
pnlPg3.Attributes.Add("display", "none");
pnlPg4.Visible = true
pnlPg4.Attributes.Add("display", "none");

then in your HTML add

<link href="print.css" type="text/css" rel="stylesheet" media="print">

print.css:
--------------
#pnlPg1 { display:; }
#pnlPg2 { display:; }
#pnlPg3 { display:; }
#pnlPg4 { display:; }
#pnlPg5 { display:; }


When you change the Visible Property in .NET it doesn't ever render the
control to the browser. If you have all the Visible Properties set to true
and use the css style display attribute = "" (blank-visible) or "none"
(invisible). Then every panel is rendered to the browser and you control
the visiblity on the client side using CSS

So the page uses the default CSS from you code on the screen layout, then
when you print using the it uses the printCSS and will make all panels
visible.

Let us know if this works.
 
A

addup

what's "normal" anyway.

While *I* wouldn't do it this way, there's nothing wrong with your
approach

For your case
Set up another command button btnPrint

Private Sub btnPrint_Click(sender as Object, e as EventArgs) Handles
btnPrint.Click
pnlPg1.Visible = True
pnlPg2.Visible = True
pnlPg3.Visible = True
pnlPg4.Visible = True
pnlPg5.Visible = True
Page.RegisterStartupScript("PrintScript", "<SCRIPT
language='javascript'>window.print(); history.back();</SCRIPT>")
End Sub
 
B

Ben Dewey

I would probably have to agree. Setting up a print page would definately be
cleaner
 
B

Blue Streak

JavaScript to the rescue!...again

I remember using a LOT of JavaScript with ASP.Classic

That gave me something to work with.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top