print a web page in c#

Last post 02-27-2006 5:34 AM by liv. 8 replies.

Sort Posts:

  • print a web page in c#

    02-22-2006, 9:50 AM
    • Member
      225 point Member
    • liv
    • Member since 02-07-2006, 9:25 AM
    • Posts 45

    Hi, I want to put a command button on my form to print the web form.

    Anyone know the code?

    I have tried window.print() but this does not work

    Thanks!

  • Re: print a web page in c#

    02-22-2006, 11:52 AM
    • Contributor
      2,842 point Contributor
    • Pluginbaby
    • Member since 11-20-2005, 8:07 PM
    • Canada
    • Posts 484
    • TrustedFriends-MVPs

    Hi,

    What king of code do you use ?

    You should use client side code to do this,
    with an asp:button :

    <asp:Button ID="Button1" runat="server" CausesValidation="False" OnClientClick="javascript:self.print();return false;" Text="Button" UseSubmitBehavior="False" />

    But it would be easier with a regular html button..

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Laurent Duveau
    Silverlight MVP / Silverlight Insider
    http://weblogs.asp.net/lduveau/
  • Re: print a web page in c#

    02-22-2006, 11:53 AM
    • All-Star
      74,917 point All-Star
    • NC01
    • Member since 08-26-2005, 7:33 PM
    • Posts 13,917
    • TrustedFriends-MVPs

    You can do it in CodeBehind to a server-side Button:
         printButton.Attributes.Add("onclick", "JavaScript: window.print(); return false;")

    Or just add an HTML Button to your page:
         <INPUT type="button" value="Print" onclick="JavaScript:window.print();">

    NC...

     

  • Re: print a web page in c#

    02-23-2006, 1:23 PM
    • Member
      28 point Member
    • GJHDigital
    • Member since 12-26-2005, 2:29 AM
    • Posts 7
  • Re: print a web page in c#

    02-23-2006, 1:52 PM
    • Member
      225 point Member
    • liv
    • Member since 02-07-2006, 9:25 AM
    • Posts 45

    Unfortunately none of these work, maybe because im using an older version on Visual Studio.Net, i cant find any html buttons and the other code shows up errors.

    Thanks

  • Re: print a web page in c#

    02-23-2006, 3:28 PM
    • All-Star
      74,917 point All-Star
    • NC01
    • Member since 08-26-2005, 7:33 PM
    • Posts 13,917
    • TrustedFriends-MVPs

    I've tried that in Versions 1.0, 1.1, and 2.0 with no problem.

    What's the errors that show up?

    NC...

     

  • Re: print a web page in c#

    02-23-2006, 4:04 PM
    • Contributor
      2,842 point Contributor
    • Pluginbaby
    • Member since 11-20-2005, 8:07 PM
    • Canada
    • Posts 484
    • TrustedFriends-MVPs

    Ok my code was for ASP.NET 2.0

    But the code from NCO1 should work for you.

    (If this has answered your question, please click on "Mark as Answer" on this post. Thank you!)

    Laurent Duveau
    Silverlight MVP / Silverlight Insider
    http://weblogs.asp.net/lduveau/
  • Re: print a web page in c#

    02-23-2006, 8:34 PM
    • All-Star
      74,917 point All-Star
    • NC01
    • Member since 08-26-2005, 7:33 PM
    • Posts 13,917
    • TrustedFriends-MVPs

    Yeah, I don't understand why not. It arouses suspicion though when he says >>i cant find any html buttons<< since I know of no version that doesn't have the HTML tab on the Toolbox with all of the HTML controls in them. Why not just copy and paste the button definition into the HTML view?

    <INPUT type="button" value="Print" onclick="JavaScript:window.print();">

    NC...

     

  • Re: print a web page in c#

    02-27-2006, 5:34 AM
    • Member
      225 point Member
    • liv
    • Member since 02-07-2006, 9:25 AM
    • Posts 45
    Thanks, i got it to work with the html buttons
Page 1 of 1 (9 items)