By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,137 Members | 2,242 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,137 IT Pros & Developers. It's quick & easy.

ASP.NET page, hiding certain controls when printing

P: n/a
I have an ASP.NET (VB) form that has two drop downs, a horizontal rule and a
button. The button invokes a stored procedure and several tables are
created on the page with data populated. I want to create a link to print
the page, but I don't want the drop downs or the button to print, only the
tables. How can this be done? I know how to use a CSS file to disallow the
entire page from being printed, but I don't know how to apply this to only
certain controls. Any advice is greatly appreciated.

Thanks
Apr 11 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Private Sub lnkPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lnkPrint.Click

m_bPrint = True

GetDBData()

UpdateDataView()

Me.NavigationControl1.Visible = False

Me.NavigationControl2.Visible = False

Me.lnkPrint.Visible = False

Me.imgPrint.Visible = False

Me.lblAppTitle.Font.Size = m_fntUnit

Me.lblBanner.Font.Size = m_fntUnit

Me.lblReportHeader.Font.Size = m_fntUnit

Me.lblLoginBar.Font.Size = m_fntUnit

Me.dgDataGrid.Font.Size = m_fntUnit

m_bPrint = False

Response.Write("<script>window.print();</script>")

End Sub

"J Ames" <j_********@yahoo.com> wrote in message
news:OD**************@TK2MSFTNGP02.phx.gbl...
I have an ASP.NET (VB) form that has two drop downs, a horizontal rule and
a button. The button invokes a stored procedure and several tables are
created on the page with data populated. I want to create a link to print
the page, but I don't want the drop downs or the button to print, only the
tables. How can this be done? I know how to use a CSS file to disallow
the entire page from being printed, but I don't know how to apply this to
only certain controls. Any advice is greatly appreciated.

Thanks

Apr 11 '06 #2

P: n/a
i'm not sure why you'd want print through a link rather than just using the
browsers print menu item.
this sure seems like doing things the hard way
just setup a second css and include it in your AFTER all other stylesheets
include the attribue media="print"

create a class in this stylesheet create a class as such :
..noprint
{
position:absolute;
top:-10000;
}
just making items invisible causes havoc with some browsers - you have to
physically move these items out of view
you may have to play with visible, width , height as well.
and override any other classes' attributes as required - font size ,
positions etc.

then assign this class to any items you want to hide when printing

<input type='button' class='noprint />

You can use this technique to print something completely different than what
is viewed in the browser by over riding class properties.

You can also use this technique to hide items in the browser view and
display them when printing

check out http://www.hgha.ca/Rep/PeeweeB.htm?tab=Schedule (or any other page
on this site ) and compare what you see in the browser to what you see in
print/preview.

Gerry


"Jeff Dillon" <je********@hotmail.com> wrote in message
news:Oq**************@TK2MSFTNGP05.phx.gbl...
Private Sub lnkPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lnkPrint.Click

m_bPrint = True

GetDBData()

UpdateDataView()

Me.NavigationControl1.Visible = False

Me.NavigationControl2.Visible = False

Me.lnkPrint.Visible = False

Me.imgPrint.Visible = False

Me.lblAppTitle.Font.Size = m_fntUnit

Me.lblBanner.Font.Size = m_fntUnit

Me.lblReportHeader.Font.Size = m_fntUnit

Me.lblLoginBar.Font.Size = m_fntUnit

Me.dgDataGrid.Font.Size = m_fntUnit

m_bPrint = False

Response.Write("<script>window.print();</script>")

End Sub

"J Ames" <j_********@yahoo.com> wrote in message
news:OD**************@TK2MSFTNGP02.phx.gbl...
I have an ASP.NET (VB) form that has two drop downs, a horizontal rule anda button. The button invokes a stored procedure and several tables are
created on the page with data populated. I want to create a link to printthe page, but I don't want the drop downs or the button to print, only thetables. How can this be done? I know how to use a CSS file to disallow
the entire page from being printed, but I don't know how to apply this to
only certain controls. Any advice is greatly appreciated.

Thanks


Apr 12 '06 #3

P: n/a
NoPrint didn't want to work with usercontrols. I'm sure I could get it to
work if I kept at it.

We are an IE only shop here..

Plus the users WANTED a print button. Yahoo, MapQuest and many others have a
print button

But I hear ya...

"gerry" <ge**@nospam.nospam> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
i'm not sure why you'd want print through a link rather than just using
the
browsers print menu item.
this sure seems like doing things the hard way
just setup a second css and include it in your AFTER all other stylesheets
include the attribue media="print"

create a class in this stylesheet create a class as such :
.noprint
{
position:absolute;
top:-10000;
}
just making items invisible causes havoc with some browsers - you have to
physically move these items out of view
you may have to play with visible, width , height as well.
and override any other classes' attributes as required - font size ,
positions etc.

then assign this class to any items you want to hide when printing

<input type='button' class='noprint />

You can use this technique to print something completely different than
what
is viewed in the browser by over riding class properties.

You can also use this technique to hide items in the browser view and
display them when printing

check out http://www.hgha.ca/Rep/PeeweeB.htm?tab=Schedule (or any other
page
on this site ) and compare what you see in the browser to what you see in
print/preview.

Gerry


"Jeff Dillon" <je********@hotmail.com> wrote in message
news:Oq**************@TK2MSFTNGP05.phx.gbl...
Private Sub lnkPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lnkPrint.Click

m_bPrint = True

GetDBData()

UpdateDataView()

Me.NavigationControl1.Visible = False

Me.NavigationControl2.Visible = False

Me.lnkPrint.Visible = False

Me.imgPrint.Visible = False

Me.lblAppTitle.Font.Size = m_fntUnit

Me.lblBanner.Font.Size = m_fntUnit

Me.lblReportHeader.Font.Size = m_fntUnit

Me.lblLoginBar.Font.Size = m_fntUnit

Me.dgDataGrid.Font.Size = m_fntUnit

m_bPrint = False

Response.Write("<script>window.print();</script>")

End Sub

"J Ames" <j_********@yahoo.com> wrote in message
news:OD**************@TK2MSFTNGP02.phx.gbl...
>I have an ASP.NET (VB) form that has two drop downs, a horizontal rule and >a button. The button invokes a stored procedure and several tables are
>created on the page with data populated. I want to create a link to print >the page, but I don't want the drop downs or the button to print, only the >tables. How can this be done? I know how to use a CSS file to disallow
>the entire page from being printed, but I don't know how to apply this
>to
>only certain controls. Any advice is greatly appreciated.
>
> Thanks
>



Apr 12 '06 #4

P: n/a
wrap your user control content in a panel and add the noprint class to the
panel's CssClass attribute or in a div and add noprint to the div class - it
works - make sure this isn't a typo or a case issue
"Jeff Dillon" <je********@hotmail.com> wrote in message
news:e1**************@TK2MSFTNGP02.phx.gbl...
NoPrint didn't want to work with usercontrols. I'm sure I could get it to
work if I kept at it.

We are an IE only shop here..

Plus the users WANTED a print button. Yahoo, MapQuest and many others have a print button

But I hear ya...

"gerry" <ge**@nospam.nospam> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
i'm not sure why you'd want print through a link rather than just using
the
browsers print menu item.
this sure seems like doing things the hard way
just setup a second css and include it in your AFTER all other stylesheets include the attribue media="print"

create a class in this stylesheet create a class as such :
.noprint
{
position:absolute;
top:-10000;
}
just making items invisible causes havoc with some browsers - you have to physically move these items out of view
you may have to play with visible, width , height as well.
and override any other classes' attributes as required - font size ,
positions etc.

then assign this class to any items you want to hide when printing

<input type='button' class='noprint />

You can use this technique to print something completely different than
what
is viewed in the browser by over riding class properties.

You can also use this technique to hide items in the browser view and
display them when printing

check out http://www.hgha.ca/Rep/PeeweeB.htm?tab=Schedule (or any other
page
on this site ) and compare what you see in the browser to what you see in print/preview.

Gerry


"Jeff Dillon" <je********@hotmail.com> wrote in message
news:Oq**************@TK2MSFTNGP05.phx.gbl...
Private Sub lnkPrint_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles lnkPrint.Click

m_bPrint = True

GetDBData()

UpdateDataView()

Me.NavigationControl1.Visible = False

Me.NavigationControl2.Visible = False

Me.lnkPrint.Visible = False

Me.imgPrint.Visible = False

Me.lblAppTitle.Font.Size = m_fntUnit

Me.lblBanner.Font.Size = m_fntUnit

Me.lblReportHeader.Font.Size = m_fntUnit

Me.lblLoginBar.Font.Size = m_fntUnit

Me.dgDataGrid.Font.Size = m_fntUnit

m_bPrint = False

Response.Write("<script>window.print();</script>")

End Sub

"J Ames" <j_********@yahoo.com> wrote in message
news:OD**************@TK2MSFTNGP02.phx.gbl...
>I have an ASP.NET (VB) form that has two drop downs, a horizontal rule

and
>a button. The button invokes a stored procedure and several tables are >created on the page with data populated. I want to create a link to

print
>the page, but I don't want the drop downs or the button to print, only

the
>tables. How can this be done? I know how to use a CSS file to disallow >the entire page from being printed, but I don't know how to apply this
>to
>only certain controls. Any advice is greatly appreciated.
>
> Thanks
>



Apr 13 '06 #5

P: n/a
gerry wrote:
i'm not sure why you'd want print through a link rather than just
using the browsers print menu item.
this sure seems like doing things the hard way

just setup a second css and include it in your AFTER all other
stylesheets include the attribue media="print"

create a class in this stylesheet create a class as such :
.noprint
{
position:absolute;
top:-10000;
}
just making items invisible causes havoc with some browsers - you
have to physically move these items out of view


This works in IE6, FF1+, Opera (all on Windows):-

@media print
{
.noprint
{
display: none;
}
}

Which browsers do you find go wrong with display:none?

Andrew
Apr 13 '06 #6

P: n/a
Hi Andrew,
off the top I don't recall - seems to me it was netscape 8 and under some
circumstance this resulted in a black hole being rendered where the hidden
element would otherwise appear.
I just did a quick test and couldn't get it to happen so I'm not sure what
the exact details were - I guess that's the kind of thing I should be
keeping track of.

It could be that this is a doh! moment and the problem was actually with
trying to use visibility:hidden rather than display:none

Gerry

"Andrew Morton" <ak*@in-press.co.uk.invalid> wrote in message
news:uB**************@TK2MSFTNGP04.phx.gbl...
gerry wrote:
i'm not sure why you'd want print through a link rather than just
using the browsers print menu item.
this sure seems like doing things the hard way

just setup a second css and include it in your AFTER all other
stylesheets include the attribue media="print"

create a class in this stylesheet create a class as such :
.noprint
{
position:absolute;
top:-10000;
}
just making items invisible causes havoc with some browsers - you
have to physically move these items out of view


This works in IE6, FF1+, Opera (all on Windows):-

@media print
{
.noprint
{
display: none;
}
}

Which browsers do you find go wrong with display:none?

Andrew

Apr 13 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.