SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    conditional print

    I am coding in asp.net (VB.net). My form has assorted fields and 2 buttons: one button to save the data and one button to print the form. I use simple javascript to print the form. I would like to make printing conditional on whether or not the user has clicked on the Save button. If the user hasn't saved, I want to disallow printing.

    Can someone suggest how I can do this?

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    attach an onclick event handler to the Save button. Have this handler set a global variable called "canprint" which is set by default to false in global scope. When onclick is met, it sets canprint to true.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,826
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You can't stop someone from printing the page just by pressing their browser print button unless you have the media=print stylesheet set up to hide the page content and if you do that and enable the page print using Javascript then you leave those without Javascript with no way to print the page at all.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Member
    Join Date
    Jun 2006
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you both for responding!

    Chris: I modified what you suggested and I have it running well now.

    Stephen: I am aware of what you say but this application is for in-house use only. All my users have javascript. But thanks for reminding me of the danger.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •