Re: window.print() and postpack, how both works?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Anders Norås [MCAD] (anders.noras_at_objectware.no)
Date: 12/28/04


Date: Tue, 28 Dec 2004 14:41:19 +0100


> In the msdn.microsoft.com/library most of the articles have an "print"
> option. But the "print" button is different from the javascripts
> "window.print()" method. It postpacks the page and then invokes the
> window.print () method. I couldn't found out the way it works. I need to
> do something like this, can any body help me?

Emit the javascript code to print the page in the click event handler. Like
this:
protected void Button_Click(object sender, System.EventArgs e) {
    Page.RegisterStartupScript("PrintPage","<script
language=\"JavaScript\">window.print();</script>");
}

> Also, i got a collection, and i want to print each of the items in the
> collection to a seperate page. If i do it with the <div> tags and arrange
> the height of it, is it same as for all different printers. Is there
> another way for it.

Use the page-break-before or page-break-after CSS styles to control page
breaks when printing.

<HR style="page-break-before: always;">
<!--- HTML to be on the page -->

You cannot use the window.print() method to print the contents of a
collection. Therefore you'll have to render each element as HTML. Use HTML
code similar to the example above to force page breaks.

Anders Norås
http://dotnetjunkies.com/weblog/anoras/



Relevant Pages

  • Re: Forms in table cells modify cell height - grrr
    ... and it has been required ever since HTML ... a page might be generated by JavaScript code but the ... The user base is our engineers, our NOC's engineers, and some of ... Posting a URL is still the best approach in HTML problems. ...
    (alt.html)
  • Web Browser interop problem - "Class does not support automation"
    ... WebBrowser ActiveX control) in order to display HTML pages. ... embedded web browser - a containing application gives the WebBrowser a COM ... Javascript code is unable to call window.external object, ... It happened on every Windows ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Use a variable to avoid repeatedly typing URLs?
    ... Here is a common problem: I have many links on a web page, ... all pointing to different pages on the same domain (e.g., ... Is there an easy way to specify somewhere in my html a ... I hope my JavaScript code is correct...;) consult in comp.lang.javascript if you need to.. ...
    (comp.infosystems.www.authoring.html)
  • Re: Problem with AJAX calls in IE: function oes not receive returned value after one time
    ... HTML content is placed on the desired place. ... anchor tag where the javascript code is placed in the href attribute. ... On this case IE won't be fussy and will accept your HTML output ... but I think my onClick event is working fine. ...
    (comp.lang.javascript)
  • Re: Forms in table cells modify cell height - grrr
    ... By HTML versions from HTML 4.0 onwards, the meaning of a form element is undefined unless it has an action attribute with a http URL. ... a page might be generated by JavaScript code but the user might then disable scripting. ... To take a less far-fetched example, an author might just goof things up and e.g. omit the JavaScript code that prevents normal form submission.) ... Posting a URL is still the best approach in HTML problems. ...
    (alt.html)