Hi, I have a web page which is developed using ASP.net code behind is VB.net. I want to print the page by clicking HTML button control but I dont want to print the print button control which is there in web page. I tried with window.print() but it is printing the control also. please help me out. thanks in advance.

Raju

You need to handle visibility of the object by using CSS media styles. If you dont want your button (or any object on page) to print add this code to your CSS styles:

@media print
{
	.PrintButton{
		display:none;
	}
}

@media screen
{
	.PrintButton{
		display:block;
	}
}

and attach this class to yout button like:

<input id="btnPrint" class="PrintButton" />

Thanks for the response, I tried but I am getting the HTMLButton Control on my printed page, can you give me some more clarity.

Raju5725

You need to handle visibility of the object by using CSS media styles. If you dont want your button (or any object on page) to print add this code to your CSS styles:

@media print
{
    .PrintButton{
        display:none;
    }
}
 
@media screen
{
    .PrintButton{
        display:block;
    }
}

and attach this class to yout button like:

<input id="btnPrint" class="PrintButton" />

It has to work! Here is the code I have just tested and it works, I have tested it on IE, Firefox, Opera. I have put styles in the same document for clarity.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Hide print button</title>
    <style type="text/css" media="screen">
    .PrintButton{
        display:block;
    }
    </style>
    <style type="text/css" media="print">
    .PrintButton{
        display:none;
    }
    </style>
</head>
<body>
    <form id="PrintForm" action="Print.htm">
        <h1>
            Test printing with hiden button</h1>
        This is just a test text for printing.<br />
        <br />
        <input id="btnPrint" type="button" value="Print page" class="PrintButton" onclick="window.print();" />
    </form>
</body>
</html>

This is code for the entire page. Try it, it works. :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.