I have an aspx web page that loads an ascx control that's populated
with various items ( in a datalist ). Select an item and the page
reloads and the datalist now shows the details.
From here I want to put a print option in, a button that will either
immediately print the contents of the datalist or maybe pop-up
something with just the currently viewed datalist contents in it (
leaving the user to print from the browser ).
But I'm not sure how best to go about it, I've been trying out some
javascript ideas I found here ( I've no idea about js, to be honest )
but with them I get a "'CallPrint ' is not a member of
'ASP.ItmDetail_ ascx' " error
eg itmdetail.ascx :
<DIV id="divprint">
<asp:DataList id="Datalist2" ..>
asp:button ID="btnPrint" onClick="CallPr int('divPrint') ;" Runat=Server
/>
itmDetail.ascx. vb :
Page_load
....[snip]
' hide the 'All News' DataList1
Panel1.Visible = True
Panel2.Visible = False
Datalist2.DataS ource = dr
Datalist2.DataB ind()
dr.Close()
cn.Close()
RegScript()
Private Sub RegScript()
Dim scriptstring As String = "<script language=Javasc ript>
function CallPrint(strid ) { "
scriptstring += "var prtContent =
document.getEle mentById(strid) ;"
scriptstring += "var WinPrint =
window.open('', '','letf=0,top= 0,width=1,heigh t=1,toolbar=0,s crollbars=0,sta tus=0');"
scriptstring +=
"WinPrint.docum ent.write(prtCo ntent.innerHTML );"
scriptstring += "WinPrint.docum ent.close();"
scriptstring += "WinPrint.focus ();"
scriptstring += "WinPrint.print ();"
scriptstring += "WinPrint.close ();"
scriptstring += "prtContent.inn erHTML=strOldOn e; }"
scriptstring += "</script>"
If (Not Page.IsStartupS criptRegistered ("Startup")) Then
Page.RegisterSt artupScript("St artup", scriptstring)
End If
End Sub
Not sure whether to pursue this line, I'm doing a lot of cut/paste and
getting highy confised. Are there any other ways to get a pop-up of the
contents of the datalist?
Suggestions welcome,
Thank you,
Bob