What print options from ascx control with datalist

  • Thread starter yer darn tootin
  • Start date
Y

yer darn tootin

Ahoy,

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="CallPrint('divPrint');" Runat=Server
/>


itmDetail.ascx.vb :

Page_load
....[snip]

' hide the 'All News' DataList1
Panel1.Visible = True
Panel2.Visible = False

Datalist2.DataSource = dr
Datalist2.DataBind()

dr.Close()
cn.Close()
RegScript()

Private Sub RegScript()
Dim scriptstring As String = "<script language=Javascript>
function CallPrint(strid) { "
scriptstring += "var prtContent =
document.getElementById(strid);"
scriptstring += "var WinPrint =
window.open('','','letf=0,top=0,width=1,height=1,toolbar=0,scrollbars=0,status=0');"
scriptstring +=
"WinPrint.document.write(prtContent.innerHTML);"
scriptstring += "WinPrint.document.close();"
scriptstring += "WinPrint.focus();"
scriptstring += "WinPrint.print();"
scriptstring += "WinPrint.close();"
scriptstring += "prtContent.innerHTML=strOldOne; }"
scriptstring += "</script>"

If (Not Page.IsStartupScriptRegistered("Startup")) Then
Page.RegisterStartupScript("Startup", 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
 
Y

yer darn tootin

I think I have it.

Added this to page_load :
Button2.Attributes.Add("onclick", "javascript:CallPrint('divPrint');")

and changed the button to
<asp:Button id="Button2" runat="server" Text="Print"></asp:Button>

Have printed something now, if a little weird looking.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top