Reputation: 1
I have a button in asp.net (c#) that I want after click this button I could print from my html table that is in a update panel ,I only want Print my html table not all page is there any component? thanx very much
Upvotes: 0
Views: 2814
Reputation: 3401
You can use CSS classes to define media type like @print, @screen and then mark appropriate parts of your webapge with those classes.
For the button to do the print, you will need to add: onClientClick="window.print()"
to the button's definition.
Use CSS like this:
@media print
{
printOnly {display:block;}
screenOnly {display:none;}
}
@media screen
{
printOnly {display:none;}
screenOnly {display:block;}
}
Then simply decorate your DIVs or other elements with the classes:
<div class="screenOnly">this will not print but will show on screen</div>
or
<div class="printOnly">this will not show on screen but will print</div>
Upvotes: 0
Reputation: 33183
2 ways to handle it:
Straight from W3c:
http://www.w3.org/TR/CSS2/media.html
Read specifically about print media, it means you can define a .css file in your asp.net project with the media type "print":
@media print {
/* style sheet for print goes here */
}
This is nice because you can now define CSS to hide all elements on your screen:
display:none
Except the div / table of your choice:
#myDiv {
display: block;
}
In your asp.net page you have this define:
<link rel="stylesheet" media="print" title="Printer-Friendly Style"
type="text/css" href="printStyle.css">
This tells your application to use the printStyle.css
file when it comes to printing your page.
And once you do try to print the app will use printStyle and all the formatting and styles you have defined.
Here is a good example: https://web.archive.org/web/20200724145536/http://www.4guysfromrolla.com:80/demos/printMediaCss.html
For the second point, if you are running SQL Server, reporting services is free. Of course you will need to set this up and deploy reports. Its a bit out of the scope of this question. If you do have reporting services you may want to open a new topic and ask questions about it. Otherwise just create a print style css file.
Upvotes: 3
Reputation: 8584
You can probably use the CSS @print Media Type to hide the stuff you don't want to print.
Check out the w3 Schools tutorial for a basic overview.
Upvotes: 0