How can I print the content of an ASP.NET page (C#)?

Discussion in 'ASP .Net' started by Steve Kershaw, Oct 13, 2006.

  1. Hello,

    I have a web page with a coupon that I would like to print when the
    user clicks on the "print" button. How can I do this in C#?

    Thanks
    Steve
    Steve Kershaw, Oct 13, 2006
    #1
    1. Advertising

  2. Steve Kershaw

    apathetic Guest

    Steve Kershaw wrote:
    > I have a web page with a coupon that I would like to print when the
    > user clicks on the "print" button. How can I do this in C#?


    You are going to need to clarify here. Are you trying to make an
    ASP.NET print button in C#? The only way to send the print command to
    the browser would be to render out some Javascript saying
    window.print() in one of your event handlers.

    Tim
    apathetic, Oct 13, 2006
    #2
    1. Advertising

  3. <asp:button ... onClickClick="javascript: window.print();" ... />

    --

    Bruno Alexandre
    KĂžbenhavn, Danmark

    "a Portuguese in Denmark"

    Blog. http://balexandre.blogspot.com/
    Photos. http://www.flickr.com/photos/balexandre/


    "Steve Kershaw" <> wrote in message
    news:...
    > Hello,
    >
    > I have a web page with a coupon that I would like to print when the
    > user clicks on the "print" button. How can I do this in C#?
    >
    > Thanks
    > Steve
    >
    Bruno Alexandre, Oct 13, 2006
    #3
  4. apathetic wrote:
    > Steve Kershaw wrote:
    > > I have a web page with a coupon that I would like to print when the
    > > user clicks on the "print" button. How can I do this in C#?

    >
    > You are going to need to clarify here. Are you trying to make an
    > ASP.NET print button in C#? The only way to send the print command to
    > the browser would be to render out some Javascript saying
    > window.print() in one of your event handlers.
    >
    > Tim

    Thanks that solved the problem!
    I just entered window.print() in the "OnClientClick" textbox in the
    Properties for the <asp:Button...> control and that did the trick!

    Thanks again Tim
    Steve
    Steve Kershaw, Oct 13, 2006
    #4
  5. Hi, did this simply print the page as if you would click file and print, or
    are you able to print only certain objects on a form for instance?

    "Steve Kershaw" wrote:

    >
    > apathetic wrote:
    > > Steve Kershaw wrote:
    > > > I have a web page with a coupon that I would like to print when the
    > > > user clicks on the "print" button. How can I do this in C#?

    > >
    > > You are going to need to clarify here. Are you trying to make an
    > > ASP.NET print button in C#? The only way to send the print command to
    > > the browser would be to render out some Javascript saying
    > > window.print() in one of your event handlers.
    > >
    > > Tim

    > Thanks that solved the problem!
    > I just entered window.print() in the "OnClientClick" textbox in the
    > Properties for the <asp:Button...> control and that did the trick!
    >
    > Thanks again Tim
    > Steve
    >
    >
    =?Utf-8?B?QW5kcmU=?=, Oct 14, 2006
    #5
  6. Steve Kershaw

    apathetic Guest

    Andre wrote:
    > Hi, did this simply print the page as if you would click file and print, or
    > are you able to print only certain objects on a form for instance?


    Javascript window.print() just calls the print command of the browser,
    so you get the whole page. You would need to use CSS with
    media="print" set, or spawn a new browser window in order to
    selectively print your content.

    Regards,
    apathetic
    apathetic, Oct 14, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hazz
    Replies:
    6
    Views:
    49,536
    SkyUCHC
    Jun 9, 2010
  2. Rolf Welskes
    Replies:
    7
    Views:
    955
    Steven Cheng[MSFT]
    Aug 22, 2006
  3. Ben
    Replies:
    5
    Views:
    5,278
  4. keto
    Replies:
    0
    Views:
    924
  5. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    346
    David Cournapeau
    Dec 30, 2008
Loading...

Share This Page