Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. print button.

print button.

Scheduled Pinned Locked Moved ASP.NET
csharphtmlasp-nethelp
9 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kunal P
    wrote on last edited by
    #1

    hi i wanted to build a print button in asp.net 2.0 i wrote the following code "codebehind" protected void Button1_Click(object sender, EventArgs e) { Button1.Attributes.Add("onClick","window.print()"); Button1.Visible = false; } now.. the button does disappear, but the print window doesnt come up. please help.. and i dont want a html input button.

    Kunal

    K 1 Reply Last reply
    0
    • K Kunal P

      hi i wanted to build a print button in asp.net 2.0 i wrote the following code "codebehind" protected void Button1_Click(object sender, EventArgs e) { Button1.Attributes.Add("onClick","window.print()"); Button1.Visible = false; } now.. the button does disappear, but the print window doesnt come up. please help.. and i dont want a html input button.

      Kunal

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      For this code to work you need to add the attributes before the button is clicked. So on the page load event do if (!IsPostback) { Button1.Attributes.Add("onClick","window.print()"); } Then it should work like you want it to. Hope that helps. Ben

      K 1 Reply Last reply
      0
      • K kubben

        For this code to work you need to add the attributes before the button is clicked. So on the page load event do if (!IsPostback) { Button1.Attributes.Add("onClick","window.print()"); } Then it should work like you want it to. Hope that helps. Ben

        K Offline
        K Offline
        Kunal P
        wrote on last edited by
        #3

        the thing worked, but theer`s a little problem. i want the button to go invisible, so that when the printing is done, the button does not show up. right now as i click the button, the print window comes, and then the button goes invisible.

        Kunal

        K 1 Reply Last reply
        0
        • K Kunal P

          the thing worked, but theer`s a little problem. i want the button to go invisible, so that when the printing is done, the button does not show up. right now as i click the button, the print window comes, and then the button goes invisible.

          Kunal

          K Offline
          K Offline
          kubben
          wrote on last edited by
          #4

          You might want to get rid of the codebehind and do something like this: Change this line: Button1.Attributes.Add("onClick","window.print()"); to: Button1.Attributes.Add("onClick","document.getElementById("+Button1.ClientId+").style.visibility = 'hidden';window.print();"); I think that should work for you. Ben

          K 1 Reply Last reply
          0
          • K kubben

            You might want to get rid of the codebehind and do something like this: Change this line: Button1.Attributes.Add("onClick","window.print()"); to: Button1.Attributes.Add("onClick","document.getElementById("+Button1.ClientId+").style.visibility = 'hidden';window.print();"); I think that should work for you. Ben

            K Offline
            K Offline
            Kunal P
            wrote on last edited by
            #5

            kubben wrote:

            You might want to get rid of the codebehind and do something like this:

            did get rid of the codebehind, removed the defintion for "Button1_Click". and placed the following code in the page_load event if (!IsPostBack) { Button1.Attributes.Add("onClick", "document.getElementById(" + Button1.ClientID + ").style.visibility = 'hidden';window.print();"); } but nothing seems to happen at all. nor does the button disappear, and neither does the print window come up

            Kunal

            K 1 Reply Last reply
            0
            • K Kunal P

              kubben wrote:

              You might want to get rid of the codebehind and do something like this:

              did get rid of the codebehind, removed the defintion for "Button1_Click". and placed the following code in the page_load event if (!IsPostBack) { Button1.Attributes.Add("onClick", "document.getElementById(" + Button1.ClientID + ").style.visibility = 'hidden';window.print();"); } but nothing seems to happen at all. nor does the button disappear, and neither does the print window come up

              Kunal

              K Offline
              K Offline
              kubben
              wrote on last edited by
              #6

              Ok I did a little playing. It looks like you will need to create a javascript funciton. In the header section of your html page you need this function: Your page name here function doPrint(button) { button.style.visibility = "hidden"; window.print(); return false; } Then in the page load event do this: Button1.Attributes.Add("onClick", "return doPrint(" + Button1.ClientID + ");"); That will work. NOTE as soon as your page posts back to the server the print button will show up again. Hope that helps. Ben

              K 1 Reply Last reply
              0
              • K kubben

                Ok I did a little playing. It looks like you will need to create a javascript funciton. In the header section of your html page you need this function: Your page name here function doPrint(button) { button.style.visibility = "hidden"; window.print(); return false; } Then in the page load event do this: Button1.Attributes.Add("onClick", "return doPrint(" + Button1.ClientID + ");"); That will work. NOTE as soon as your page posts back to the server the print button will show up again. Hope that helps. Ben

                K Offline
                K Offline
                Kunal P
                wrote on last edited by
                #7

                thanks ben.. uve been a great help to me.. i dunno if ud remember helping me.. but i do remember the relief i get when i see the answer is from kubben in the forum.. i know.. this problem is no more a problem.. :) thx again...

                Kunal

                K 1 Reply Last reply
                0
                • K Kunal P

                  thanks ben.. uve been a great help to me.. i dunno if ud remember helping me.. but i do remember the relief i get when i see the answer is from kubben in the forum.. i know.. this problem is no more a problem.. :) thx again...

                  Kunal

                  K Offline
                  K Offline
                  kubben
                  wrote on last edited by
                  #8

                  Glad I could help out. Sorry I didn't get it right the first time. Ben

                  K 1 Reply Last reply
                  0
                  • K kubben

                    Glad I could help out. Sorry I didn't get it right the first time. Ben

                    K Offline
                    K Offline
                    Kunal P
                    wrote on last edited by
                    #9

                    no problemo.. all is well that ends well..:)

                    Kunal

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups