datalist, js function, printing - is innerhtml ignoring <div class="x"> read from SQL db

  • Thread starter yer darn tootin
  • Start date

Y

yer darn tootin

Here's the scenario: I have a javascript function taking the contents
of a datalist ( content from a SQL db ) and opening it in a new window
to allow the user to print. The pop-up window successfully applies the
formatting from the datalist ( ie the dl's <ItemStyle> properties ),
but ignores any of the formatting 'hard coded' into the SQL data being
returned, eg things like <div class="newpara">. This in-table
formatting appears OK on the normal web page when the datalist is
loaded, it's just not being kept when the new window for print pops-up.

Any ideas, or workaround?

Private Sub RegPrintScript()
imgPrint.Attributes.Add("onclick",
"javascript:CallPrint('divPrint');")

Dim scriptstring As String = "<script language=Javascript>
function CallPrint(strid) { "
scriptstring += "var prtContent =
document.getElementById(strid);"
scriptstring += "var WinPrint =
window.open('','','left=100,top=150,width=600,height=500,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>"

'Page.RegisterClientScriptBlock("clientScript", scriptstring)

If (Not Page.IsClientScriptBlockRegistered("clientScript"))
Then
Page.RegisterClientScriptBlock("clientScript",
scriptstring)
End If
End Sub


The datalist is enclosed in a <DIV id="divprint"> </DIV> tag.
 
Ad

Advertisements

Y

yer darn tootin

I've just realised that the various <div class='x'> styling from
datalist items are being ignored too.

<ItemStyle Font-Size="10pt" Font-Names="=Arial" BorderWidth="0px"
ForeColor="#000033"
BackColor="White"></ItemStyle>
<ItemTemplate>
<div class="Title">
<%# DataBinder.Eval(Container.DataItem, "Title") %>
</div>

Is this a known issue ( css styles ignored on client side scripting ),
or is my js function incomplete?
 
Ad

Advertisements

Y

yer darn tootin

in the spirit of goodwill here's how to read in the css page so the div
classes of the datalist are rendered to the pop-up window/for print.

scriptstring += "WinPrint.document.write('<HTML><Head><LINK
href=""printpage.css"" type=""text/css""
rel=""stylesheet""></Head><Body>'); "
scriptstring +=
"WinPrint.document.write(prtContent.innerHTML);"
scriptstring += "WinPrint.document.write('</Body></HTML>'); "

Bob
 

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