If e.PostBackValue = "print" Then
Dim javaScript As String = "<script language=JavaScript>CallPrint('" + strid + "');</" + "script>"
RegisterStartupScript("PrintWindowScript", javaScript)
End If
If e.PostBackValue = "print" Then
Dim javaScript As String = "<script language=JavaScript>CallPrint('" + strid + "');</" + "script>"
RegisterStartupScript("PrintWindowScript", javaScript)
End If
so in there, you'd have to define a "strid" variable and give it the ID of the control that you want to print, maybe something like this:
If e.PostBackValue = "print" Then
Dim strid As String = "ID of control to print here" 'Maybe ImageMap1.ClientID ??
Dim javaScript As String = "<script language=JavaScript>CallPrint('" + strid + "');</" + "script>"
RegisterStartupScript("PrintWindowScript", javaScript)
End If
e.PostBackValue = "print"
Then
Dim strid As
String = "DetailsView4"
Dim javaScript
As String =
"<script language=JavaScript>CallPrint('" + strid +
"');</" + "script>"
RegisterStartupScript(
"PrintWindowScript", javaScript)
End If
------------------------------------
I get a Warning in VWD :
Warning 1 'Public Overridable Sub RegisterStartupScript(key As String, script As String)' is obsolete: 'The recommended alternative is ClientScript.RegisterStartupScript(Type type, string key, string script).
http://go.microsoft.com/fwlink/?linkid=14202' C:\Documents and Settings\Daniel Depolito\My Documents\Visual Studio 2005\WebSites\TTGWeb\ColumnDetail.aspx.vb 27 13 C:\...\TTGWeb\
----------------------------
And when I try to execute the code. I get a message window in the browser that states:
Sammy, I don't know if that will fix it, but maybe. Sounds more like the JavaScript is being outputted and missing a quote or something.
Anyways, bring the page up in the browser and do a View Source (which will bring the rendered source up in NotePad, that's where line: 118 char:2 is) and see if that script is outputed into the HTML, and what it looks like if it is.
If it is, do a search for "DetailsView4" and make sure that there's an object for it.
Ok Danny, I just tried this and it works as it's supposed as I tested it. There were some errors in the JavaScript, so I re-wrote it. I don't know if that is what is causing your problem, but this one works:
////////////////////////////
// In the aspx file:
////////////////////////////
<script language=JavaScript>
function callPrint(elementId)
{
var printContent = document.getElementById(elementId);
var printWindow = window.open('', '', 'left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
////////////////////////////
// In the CodeBehind file:
////////////////////////////
If e.PostBackValue = "print" Then
Dim contentId As String = "DetailsView4"
Dim javaScript As String = "<script language=JavaScript>callPrint('" + contentId + "');</" + "script>"
Me.RegisterStartupScript("PrintWindowScript", javaScript) '
End If
DannyDep
Member
749 Points
316 Posts
Code to print part of a web page.
Feb 05, 2006 03:37 PM|LINK
I’m a newbie who is trying to print part of a web page.
I have followed another example on the web:
http://www.devx.com/tips/Tip/27626
to achieve the goal of only printing a part of the page.
Here is the code in my .aspx page
<script type="text/javascript" language="javascript">
function CallPrint(strid)
{
var prtContent = document.getElementById(strid);
var WinPrint = window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
WinPrint.document.write(prtContent.innerHTML);
WinPrint.document.close();
WinPrint.focus();
WinPrint.print();
WinPrint.close();
prtContent.innerHTML=strOldOne;
}
</script>
I have also defined my imagemap:
<asp:ImageMap ID="ImageMap1" runat="server" Style="position: relative" ImageUrl="~/images/TECH-BOX_02.gif">
<asp:RectangleHotSpot Bottom="45" Left="31" Right="172" Top="24" AlternateText="Printable Version" HotSpotMode="PostBack" PostBackValue="print" />
<asp:RectangleHotSpot Bottom="66" Left="31" Right="173" Top="48" AlternateText="Forward to a friend" PostBackValue="forward" HotSpotMode="PostBack" />
<asp:RectangleHotSpot Bottom="87" Left="31" Right="173" Top="69" AlternateText="Article Feed back" PostBackValue="feedback" />
</asp:ImageMap>
So how should the code look in my code behind page in order to initiate the javascript?
Partial Class ColumnDetail
Inherits System.Web.UI.Page
Protected Sub ImageMap1_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ImageMapEventArgs) Handles ImageMap1.Click
If e.PostBackValue = "print" Then
?????????????????????????????????????????????
End If
End Sub
End Class
thx.
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: Code to print part of a web page.
Feb 05, 2006 04:33 PM|LINK
If e.PostBackValue = "print" Then
Dim javaScript As String = "<script language=JavaScript>CallPrint('" + strid + "');</" + "script>"
RegisterStartupScript("PrintWindowScript", javaScript)
End If
NC...
DannyDep
Member
749 Points
316 Posts
Re: Code to print part of a web page.
Feb 11, 2006 02:55 PM|LINK
When I inserted the two lines of code into the VB post behind, I get the following error message:
Error - Name 'strid' is not declared.
I thought that is was defined in the script var line of code:
<
script type="text/javascript" language="javascript">function
CallPrint(strid){
var prtContent = document.getElementById(strid);................
................
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: Code to print part of a web page.
Feb 11, 2006 04:41 PM|LINK
Well, I found your post anyways, so here goes:
This code is in the server-side code:
If e.PostBackValue = "print" Then
Dim javaScript As String = "<script language=JavaScript>CallPrint('" + strid + "');</" + "script>"
RegisterStartupScript("PrintWindowScript", javaScript)
End If
so in there, you'd have to define a "strid" variable and give it the ID of the control that you want to print, maybe something like this:
If e.PostBackValue = "print" Then
Dim strid As String = "ID of control to print here" 'Maybe ImageMap1.ClientID ??
Dim javaScript As String = "<script language=JavaScript>CallPrint('" + strid + "');</" + "script>"
RegisterStartupScript("PrintWindowScript", javaScript)
End If
NC...
DannyDep
Member
749 Points
316 Posts
Re: Code to print part of a web page.
Feb 14, 2006 11:02 PM|LINK
Hi NC,
The control is a DetailsView.
When I included the code below:
If
e.PostBackValue = "print" Then Dim strid As String = "DetailsView4" Dim javaScript As String = "<script language=JavaScript>CallPrint('" + strid + "');</" + "script>"RegisterStartupScript(
"PrintWindowScript", javaScript) End If------------------------------------
I get a Warning in VWD :
Warning 1 'Public Overridable Sub RegisterStartupScript(key As String, script As String)' is obsolete: 'The recommended alternative is ClientScript.RegisterStartupScript(Type type, string key, string script). http://go.microsoft.com/fwlink/?linkid=14202' C:\Documents and Settings\Daniel Depolito\My Documents\Visual Studio 2005\WebSites\TTGWeb\ColumnDetail.aspx.vb 27 13 C:\...\TTGWeb\
----------------------------
And when I try to execute the code. I get a message window in the browser that states:
Line:118
Character: 2
Error: Object Required
Code: 0
URL:http://localhost/TTGWeb/ColumnDetail.aspx?ColumnID=213
------------------------------
I'm not sure where to look for line: 118 char:2. As the aspx file nor the vb file have 118 lines in them.
Also the output of the DetailsView4 is not 118 lines long either. ????
Any ideas?
thx,
ciao, Dan
sammy_1971
Member
115 Points
23 Posts
Re: Code to print part of a web page.
Feb 15, 2006 04:48 AM|LINK
Dan,
Me.GetType(), "myScript", javaScript)change
RegisterStartupScript("PrintWindowScript", javaScript) to Page.ClientScript.RegisterClientScriptBlock(
Good luck
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: Code to print part of a web page.
Feb 15, 2006 01:12 PM|LINK
Sammy, I don't know if that will fix it, but maybe. Sounds more like the JavaScript is being outputted and missing a quote or something.
Anyways, bring the page up in the browser and do a View Source (which will bring the rendered source up in NotePad, that's where line: 118 char:2 is) and see if that script is outputed into the HTML, and what it looks like if it is.
If it is, do a search for "DetailsView4" and make sure that there's an object for it.
If it isn't, Sammy's solution should fix it.
NC...
DannyDep
Member
749 Points
316 Posts
Re: Code to print part of a web page.
Feb 16, 2006 02:49 AM|LINK
Sammy, tried your suggestion. Got no response when I clicked on the hot key.
NC.
Took the pages ViewSource into VWD. Following starts at line 118 Column2:
WinPrint.document.write(prtContent.innerHTML);
Any ideas men?
thx, ciao, Dan
sammy_1971
Member
115 Points
23 Posts
Re: Code to print part of a web page.
Feb 16, 2006 11:22 AM|LINK
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: Code to print part of a web page.
Feb 16, 2006 01:43 PM|LINK
Ok Danny, I just tried this and it works as it's supposed as I tested it. There were some errors in the JavaScript, so I re-wrote it. I don't know if that is what is causing your problem, but this one works:
////////////////////////////
// In the aspx file:
////////////////////////////
<script language=JavaScript>
function callPrint(elementId)
{
var printContent = document.getElementById(elementId);
var printWindow = window.open('', '', 'left=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');
printWindow.document.write(printContent.innerHTML);
printWindow.document.close();
printWindow.focus();
printWindow.print();
printWindow.close();
}
</script>
<div id="DetailsView4">
<asp:datagrid>
columns, etc...
</asp:datagrid>
</div>
////////////////////////////
// In the CodeBehind file:
////////////////////////////
If e.PostBackValue = "print" Then
Dim contentId As String = "DetailsView4"
Dim javaScript As String = "<script language=JavaScript>callPrint('" + contentId + "');</" + "script>"
Me.RegisterStartupScript("PrintWindowScript", javaScript) '
End If
NC...