473,321 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Calling window.print from server page

Hello. I'm trying to call a function that prints the content of a div
element. I had that javascript code working, but now I must put that code in
the server side, as it is called from another component.

The problem is that it can't find the div control. Don't know why. I paste
the code here:

That's in the aspx.vb file:

Response.Write("<script>")
Response.Write(" var prtContent = document.getElementById(divPrint);")
Response.Write("var WinPrint =
window.open('','','letf=0,top=0,width=1,height=1,t oolbar=0,scrollbars=0,status=0');")
Response.Write(" WinPrint.document.write(prtContent.innerHTML);")
Response.Write(" WinPrint.document.close();")
Response.Write(" WinPrint.focus();")
Response.Write(" WinPrint.print();")
Response.Write(" WinPrint.close();")
Response.Write(" prtContent.innerHTML=strOldOne;")
Response.Write("</script>")

In the aspx file there is the div control with a datagrid inside.

--
Regards,

Diego F.


Nov 19 '05 #1
3 4419

"Diego F." <di*******@terra.es> wrote in message
news:Oz**************@tk2msftngp13.phx.gbl...
Hello. I'm trying to call a function that prints the content of a div
element. I had that javascript code working, but now I must put that code
in the server side, as it is called from another component.

The problem is that it can't find the div control. Don't know why. I paste
the code here:

That's in the aspx.vb file:

Response.Write("<script>")
Response.Write(" var prtContent = document.getElementById(divPrint);")
Response.Write("var WinPrint =
window.open('','','letf=0,top=0,width=1,height=1,t oolbar=0,scrollbars=0,status=0');")
Response.Write(" WinPrint.document.write(prtContent.innerHTML);")
Response.Write(" WinPrint.document.close();")
Response.Write(" WinPrint.focus();")
Response.Write(" WinPrint.print();")
Response.Write(" WinPrint.close();")
Response.Write(" prtContent.innerHTML=strOldOne;")
Response.Write("</script>")

In the aspx file there is the div control with a datagrid inside.

--
Regards,

Diego F.


Replace:
Response.Write(" var prtContent = document.getElementById(divPrint);")

With:
Response.Write(" var prtContent = document.getElementById('divPrint');")
HTH,
Mythran

Nov 19 '05 #2
> Replace:
Response.Write(" var prtContent = document.getElementById(divPrint);")

With:
Response.Write(" var prtContent = document.getElementById('divPrint');")


It was a mistake pasting the code. It's written as you mention.

--
Regards,

Diego F.


Nov 19 '05 #3

"Diego F." <di*******@terra.es> wrote in message
news:Oz**************@tk2msftngp13.phx.gbl...
Hello. I'm trying to call a function that prints the content of a div
element. I had that javascript code working, but now I must put that code
in the server side, as it is called from another component.

The problem is that it can't find the div control. Don't know why. I paste
the code here:

That's in the aspx.vb file:

Response.Write("<script>")
Response.Write(" var prtContent = document.getElementById(divPrint);")
Response.Write("var WinPrint =
window.open('','','letf=0,top=0,width=1,height=1,t oolbar=0,scrollbars=0,status=0');")
Response.Write(" WinPrint.document.write(prtContent.innerHTML);")
Response.Write(" WinPrint.document.close();")
Response.Write(" WinPrint.focus();")
Response.Write(" WinPrint.print();")
Response.Write(" WinPrint.close();")
Response.Write(" prtContent.innerHTML=strOldOne;")
Response.Write("</script>")

In the aspx file there is the div control with a datagrid inside.

--
Regards,

Diego F.


Try:

Dim script As String = _
"<script language=""javascript"" type=""text/javascript"">" & vbNewLine
& _
" function WindowPrint() {" & vbNewLine & _
" var prtContent = document.getElementById('divPrint');" & vbNewLine
& _
" var WinPrint = window.open(" & _
"'', '',
'letf=0,top=0,width=1,height=1,toolbar=0,scrollbar s=0,status=0');" &
vbNewLine & _
" WinPrint.document.write(prtContent.innerHTML);" & vbNewLine & _
" WinPrint.document.close();" & vbNewLine & _
" WinPrint.focus();" & vbNewLine & _
" WinPrint.print();" & vbNewLine & _
" WinPrint.close();" & vbNewLine & _
" prtContent.innerHTML=strOldOne;" & _
" }" & vbNewLine

Page.RegisterScript("WindowPrint", script)

Then, in your Page_Render, have:

Page.RegisterStartupScript("DoWindowPrint", _
"<script language=""javascript"" type=""text/javascript"">" & vbNewLine
& _
" WindowPrint();" & vbNewLine & _
"</script>" _
)

Hope this works right, off top of head...

Mythran

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RL | last post by:
Hello Perl gurus, 1. I have a web page where I can push a button (dospawn.html). 2. This button calls a CGI script (spawnboss.cgi) 3. spawnboss.cgi calls a forking perl script (forkme.pl) 4....
2
by: Harold | last post by:
I have page A with form field and a button and when button is clicked it opens page B in another window. Page B has a treeview control and that is all. When something is selected I want the page...
1
by: desmcc | last post by:
Hi, I am launching a modal dialog through the usual javascript (window.showmodaldialog). When the modal dialog is complete (ie user selects OK), the calling page then refreshes itself by setting...
22
by: stephen | last post by:
I have created an order form that users javascript to create a new html document when the customers clicks the "print page" button. Once the new document has been created it then prints the...
10
by: Tony Rice | last post by:
If I've loaded a set of functions in a webdocument like this: <script language="JavaScript" type="text/javascript" src="/js/foo.js"</script> Shouldn't I be able to call a function from...
3
by: Opa | last post by:
Hi , I have a form with javasript which launches a popup via the showModalDialog() method. I get the dialog to open, now I am trying to first get a reference to the calling form from the popup...
3
by: rgparkins | last post by:
Hi, Really stuck with this one, or the fact that I have just had a baby maybe mind mind is in meltdown and I cant figure how to solve this! I have a list of users stored in session. These...
1
by: Kbalz | last post by:
Having a really hard time finding solid examples on deploying a CR .NET applcation on my intranet. I'll explain what I've done so far, and toward the bottom is where I can't print using the report...
22
by: Archanak | last post by:
Hi, I am using 2-level CSS Drop Down Menu in my perl/CGI program. here is the code. #!c:/perl/bin/perl.exe use CGI qw(:standard);
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.