How do i print asp page on client side ?
the code
<input type="button" value="Print" onClick="window.print()">
prints the entire asp page .if i want to print only the contents of the page and not the links and other stuff .How do i do it ?
Can I get a sample code for it .

Thank you

Dani AI

Generated

A few practical options that keep only the main content on the printed page. ’s suggestion (hide unwanted DOM before printing) and ’s idea (a dedicated print page) are both valid; the cleanest, most maintainable approach is a print stylesheet that hides chrome and shows only the content container.

Use a print stylesheet (preferred)

Add a @media print rule that hides everything by default and reveals only the content block. That avoids DOM surgery and works well across browsers:

@media print {
  /* hide everything first */
  body * { visibility: hidden; }

  /* reveal the printable area (wrap main content in #printable) */
  #printable, #printable * { visibility: visible; }
  #printable { position: absolute; top: 0; left: 0; }

  /* utility class to explicitly remove items from print */
  .no-print { display: none !important; }
}

Open a minimal window with just the content (alternate)

When layout must differ dramatically, render only the content into a new window, copy necessary styles, then print and close. This avoids pop-up blockers by opening from a user action:

function printSection(id) {
  var el = document.getElementById(id);
  if (!el) return;
  var w = window.open('', '_blank', 'toolbar=0,location=0,menubar=0');
  var styles = Array.prototype.slice.call(document.querySelectorAll('link[rel="stylesheet"], style'))
    .map(function(s){ return s.outerHTML; }).join('');
  w.document.write('<!doctype html><html><head><meta charset="utf-8"><title>Print</title>' + styles + '</head><body>');
  w.document.write(el.outerHTML);
  w.document.write('</body></html>');
  w.document.close();
  setTimeout(function(){ w.print(); w.close(); }, 250);
}

Server-side print page (classic ASP)

When content needs server-side formatting, generate a print-only version (e.g., page.asp?print=1) that includes a print stylesheet and calls print on load. This is simplest for complex layouts or when removing interactive controls is easiest on the server.

Notes and troubleshooting: test print preview in multiple browsers, use !important in print CSS to override screen rules, allow a short delay before calling print() so styles load, and be aware pop-up blockers can interfere with window-based approaches.

Recommended Answers

All 2 Replies

Wel they way I use to print the whole page is by using the javascript to hide the things i dont want to appear on the print.
I use this javascript to hide the things, I pass the id of that particular HTML element whom i want to hide like the table, images etc...
Then you can call the print method to print the page.

function showhide(id)
 {
  var itm = null;
  if (document.getElementById) {
   itm = document.getElementById(id);
  } else if (document.all){
   itm = document.all[id];
  } else if (document.layers){
   itm = document.layers[id];
  }
  if (itm.style) {
   if (itm.style.display == "none") { itm.style.display = ""; }
   else { itm.style.display = "none"; }
  }
 }

therwise just use the meta print thiny. it prints an entirely different page to the one showed. so set up 2 asp pages. 1 to be viewed, 1 to be printed

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.