Adding a Print Button with Javascript

Posted by David Wier on 03/30/10 | Tips and Tricks

If you'd like to use an ASP.Net button for printing, all you need to do is :
Add this line to the Page_Load event

btnPrint.Attributes("onClick") ="javascript:window.print();"

Add a button to the page called 'btnPrint'

Technically, that's it, but, let's say you want to do something a little fancier, using DotNet. Then, add a subroutine (let's call it 'DoPrint'):

Sub doPrint(Source as Object, E as EventArgs)

            lblResults.visible="True"

            lblResults.text="Page has successfully been sent to the printer!"

End Sub

Then, add a direction to this sub, in the button's tag:

onServerclick="doPrint"





















































































































0 Comments

COMMENTS

Name:
URL:
Comment:

Comments are disabled for this article.