Categories: Printing in Silverlight Posted on 7/7/2009 12:39 PM by Ryan Shelby  Feedback (2)

I've been using the HTML Bridge in Silverlight to generate printer friendly content to an existing DIV element in my Default.aspx page.

 

The problem that I was having was everything worked great in Internet Explorer, but when I tried to view the HTML Content using Firefox or Safari, I couldn't see the text.

 

To make a long story short, the problem went away when I changed the HTML Element's innerHTML using SetProperty instead of SetAttribute.

 

Below is a quick example of creating a simple HTML Table that can be seen in Internet Explorer, Firefox and Safari.

 

Dim myDoc As System.Windows.Browser.HtmlDocument = HtmlPage.Document    'Reference Browser's Document Object.
Dim myDiv = myDoc.GetElementById("printDIV")                            'Reference existing Div element in ASPX page.
Dim myTable As HtmlElement = myDoc.CreateElement("TABLE")
Dim myCaption As HtmlElement = myDoc.CreateElement("CAPTION")
Dim myTR As HtmlElement = myDoc.CreateElement("TR")
Dim myTD As HtmlElement = myDoc.CreateElement("TD")
 
myDiv.AppendChild(m_Table)          'Add TABLE element to existing DIV.
myTable.AppendChild(m_Caption)      'Add CAPTION element to TABLE.
myTable.AppendChild(myTR)           'Add TR element to TABLE.
myTR.AppendChild(m_TD)              'Add TD element to TR.
 
myCaption.SetAttribute("innerHTML", "Table Title")  'This will NOT work in Firefox and Safari.
myCaption.SetProperty("innerHTML", "Table Title")   'This will work work in IE, Firefox and Safari.
 
myTD.SetAttribute("innerHTML", "This is a table containing 1 row and 1 cell.")  'This will NOT work in Firefox and Safari.
myTD.SetProperty("innerHTML", "This is a table containing 1 row and 1 cell.")   'This will work work in IE, Firefox and Safari.

 

Hopefully this information might save some time for anyone running into the same issue.  It took me all morning to figure this out...

 

 

Comments

marti
marti on 7/20/2009 1:58 PM Thanks, fixed problem I had with FF 3.0

I also had problem with GetElementById, IE seems to be be case insensitive, but FF is case sennsitive, so for a tag "report"

This worked in IE but not FF
HtmlPage.Document.GetElementById("Report")

Worked in IE and FF
HtmlPage.Document.GetElementById("report")


Marti
Greg
Greg on 9/2/2009 1:32 PM I appreciate seeing these helpful hints.

Thanks!

Send Feedback





biuquote
  • Comment
  • Preview
Loading