tags:

views:

68

answers:

2

Hello, I have a problem with the print preview with javascript and asp.net mvc. I take the data of a search and passes the data via JSON to a JavaScript function:

function preview (content) ( 
             debugger; 
             var result = content.get_response (). get_object (); 
             var json = eval (result); 
             var w = window.open ( 'Stampa.aspx', "Research Press", "height = 1200, width = 1000, status = yes, toolbar = no, menubar = no, location = no"); 
            w.document.open (); 

             HeadPrint + = "<table border=1>"; 
             CreateTableRicercaHead (); 
             CreateTableRicercaMain (JSON) 
             FootPrint + = "</ table>"; 

             var node = w.document.createTextNode (HeadPrint + + strPrint Footprint); 
             alert (node.data); 
             var divPrint = w.document.getElementById (PrintDocument); 
             / / divPrint.innerHTML = HeadPrint + + strPrint footprint; 
             divPrint.appendChild (node); 
             alert (divPrint.appendChild (node)); 

  CreateTableRicercaMain function (data) ( 
             for (var list in data.r) ( 
                 strPrint + = "<tr>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. UserID; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. Surname; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. Name; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. Way; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. Telephone; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. common; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. Cap; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. Province; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. CF; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. Data_Versamento; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. IdOperatore; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. Amount; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. Data_inserimento; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. Note; 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. causal 
                 strPrint + = "</ td>"; 
                 strPrint + = "<td>"; 
                 strPrint + = data.r [list]. Nr_CC; 
                 strPrint + = "</ td>"; 
             ) 

         ) 


         CreateTableRicercaHead function () ( 
             HeadPrint + = "<tr>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "UserID"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Name"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Name"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Street"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Phone"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "common"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Cap"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Province"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Cf"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Data_Versamento"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "IdOperatore"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Amount"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Data_inserimento"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Notes"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Cause"; 
             HeadPrint + = "</ th>"; 
             HeadPrint + = "<th>"; 
             HeadPrint + = "Nr_CC"; 


HeadPrint + = "</ th>"; 
         HeadPrint + = "</ tr>"; 
     )

and how you can see I try to write the result in a div with innerHTML method, because if you write it with document.write () I noticed that with the data of a certain size (4000) the display is 1 minute. , but the problem is that when I open the popup, I do not display anything is white, also if I right click-> View HTML I'm not seeing anything.Can you help me to resolve this issue?

A: 

Not sure why you would not just build the table on the serverside where it is optimal to loop. JavaScript is horrible at large loops.

I do not see a w.document.close() in your code.

epascarello
A: 

Hello and thanks for your answers, but also the server side with a certain amount of data the page is displayed very slowly. my goal was to pass data via json, setting div.innerHTML with the result, for if I put on the same page I show 4000 records in less than 1 second. and then I was thinking of opening the document and then read the div that I created the page, but does not work.

Then you advise me to do everything server side? Thanks