ASP.NET page, hiding certain controls when printing

Discussion in 'ASP .Net' started by J Ames, Apr 11, 2006.

  1. J Ames

    J Ames Guest

    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
     
    J Ames, Apr 11, 2006
    #1
    1. Advertisements

  2. J Ames

    Jeff Dillon Guest

    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
     
    Jeff Dillon, Apr 11, 2006
    #2
    1. Advertisements

  3. J Ames

    gerry Guest

    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
     
    gerry, Apr 12, 2006
    #3
  4. J Ames

    Jeff Dillon Guest

    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...
     
    Jeff Dillon, Apr 12, 2006
    #4
  5. J Ames

    gerry Guest

    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
     
    gerry, Apr 13, 2006
    #5
  6. 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
     
    Andrew Morton, Apr 13, 2006
    #6
  7. J Ames

    gerry Guest

    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
     
    gerry, Apr 13, 2006
    #7
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.