Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a javascript that prints a crystal report. It works well. Except for the part where I need to send a value to the button to delete a specific image. I am trying to send "Printed" to the button as trigger.

  <script type="text/javascript">
                          //this is for priting crystal report directly
                          function Printing() {

                              var dvReport = document.getElementById("dvReport");
                              var frame1 = dvReport.getElementsByTagName("iframe")[0];

                              var printvalue = document.createElement("INPUT"); // this is for sending trigger to button
                              printvalue.type = "hidden";
                              printvalue.name = "printvalue";

                              if (navigator.appName.indexOf("Internet Explorer") != -1 || navigator.appVersion.indexOf("Trident") != -1) {
                                  frame1.name = frame1.id;
                                  window.frames[frame1.id].focus();
                                  window.frames[frame1.id].print();

// this is for sending trigger to button
                                  printvalue.value = "Printed";
                                  document.forms[0].appendChild(printvalue);
                              }
                              else {
                                  var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
                                  frameDoc.print();

// this is for sending trigger after print();  to button but is not working
                                  printvalue.value = "Printed";
                                  document.forms[0].appendChild(printvalue);
                                 }


                          }
                          </script>


This is how I call the javascript

<asp:Button ID="Print" runat="server" Text="PRINT"
OnClientClick="Printing();"  />


This is my button click. Javascript is triggered but not sending the value in button click when printing is DONE/cancelled.

Protected Sub keywordSearch_Click(sender As Object, e As EventArgs) Handles keywordSearch.Click

     Dim printvalue As String = Request.Form("printvalue")
     If printvalue = "Printed" Then
         deletepic(Session("Request"))
        setStatus("DELETED! PRINTED!")
     End If

 End Sub


What I have tried:

I've tried putting the value and calling it in another function and is working well but when I try to merge it with the printing function the value cant be passed.

I also Tried this javascript. the button is triggered only if the Print Preview was cancelled but when Printing is executed. It wont trigger at all.
What am i missing?


function Tryial() {
                             var dvReport = document.getElementById("dvReport");
                             var frame1 = dvReport.getElementsByTagName("iframe")[0];
                             var frameDoc = frame1.contentWindow ? frame1.contentWindow : frame1.contentDocument.document ? frame1.contentDocument.document : frame1.contentDocument;
                             frameDoc.print();

                             var print_value = document.createElement("INPUT");//call
                             print_value.type = "hidden";
                             print_value.name = "print_value";

                              print_value.value = "Printed";
                             document.forms[0].appendChild(print_value);

                         }
Posted
Updated 6-Feb-18 14:45pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900