How to know click (Ok or Cancel) event from print pop-up of web browser
<p>In my application I am printing some data through a pop-up window. On loading the pop-up, the user will be prompted for to either print or cancel. I want to know which button is clicked (print or cancel) so that I can take some action based on the button clicked. The code and screenshot are given below.</p>

<pre><code>public void Print(int Id)
        {
            StringBuilder sb = BadgeHelper.preparePrintableString(Id);
            string printWindowFunc = "function printWindow() {\n" +
                                        "var z = window.print();\n alert('Return: ' + z);\n" + 
                                        "checkDocumentState();\n" +
                                      "}";
            string checkDocumentStateFunc = "function checkDocumentState() {\n" +
                                                "if (document.readyState == 'complete') {\n" +
                                                    "window.close();\n" +
                                                "}\n" +
                                                "else {\n alert('Else');\n" +
                                                    "setTimeout('checkDocumentState()', 2000);\n" +
                                                "}\n"+
                                            "}\n";

            string startingHTMLCode = "&lt;html&gt;\n" +
                                        "&lt;head&gt;\n" +
                                            "&lt;script type='text/javascript'&gt;\n " +
                                                checkDocumentStateFunc + 
                                                "\n" +
                                                printWindowFunc +
                                            "&lt;/script&gt;\n " + 
                                        "&lt;/head&gt;\n" +
                                        "&lt;body onload='printWindow();'&gt;\n";
            sb.Insert(0, startingHTMLCode);
            sb.Append("\n&lt;/body&gt;\n&lt;/html&gt;");

            Response.Write(sb.ToString());
        }
</code></pre>

<p><img src="http://i.stack.imgur.com/5rrUD.jpg" alt="enter image description here"></p>
