Andrew Chan
Andrew Chan

Reputation: 40

Control the content in printing

I got a website (using asp.net) like below:

<asp:Content>
[Header]
<asp:Content />
<asp:Content>    
[some inputbox]
[button]
[content]
<asp:Content />

Is there any way for me to print the content only(using the print function default in browser)? Like setting some attribute for the tags?

EDIT: Some addition for the solution from Arsalan Hussain: I add the style tag below the asp:content tag

<asp:Content>
    <style>
        @media print {
            .no-print {
            display: none;
            }
        }
    </style>
</asp:Content>

And use a tag to cover the part I don't want to print:

<span class="no-print">
    "Content"
</span>

Upvotes: 0

Views: 44

Answers (1)

Arsalan Hussain
Arsalan Hussain

Reputation: 66

You can use CSS to achieve this. Assign a CSS class that you want to display or vise versa. And use CSS Media Queries

@media print {
   …
}

for example

<asp:Content>
[Header class="no-print"]
<asp:Content />
<asp:Content>    
[some inputbox class="no-print"]
[button class="no-print"]
[content]
<asp:Content />



@media print {
  .no-print{display:none;}
}

and the time of printing, this css will be applied to the elements and they will not be displayed.

Upvotes: 1

Related Questions