Tuesday, February 03, 2009
If you are using a custom ASP.NET web control to render your Silverlight 2 Object tag with the HtmlTextWriter, you need to make sure to render the Object tag's param elements as self-closing. Otherwise, you will discover that IE 6, 7, and 8 will ignore the invalid XHTML 1.0 Transitional "</param>" element and load the Object tag (meaning your Silverlight app) correctly but Google Chrome and Mozilla Firefox will not.
Instead, you should render your param elements as self-closing by using the HtmlTextWriter's WriteBeginTag method and the SelfClosingTagEnd constant. According to MSDN's WriteBeginTag documentation, "the WriteBeginTag method does not write the closing angle bracket (>) of the markup element's opening tag. This allows the writing of markup attributes to the opening tag of the element." This means you can close it yourself with the SelfClosingTagEnd constant, which they do not demonstrate but is easily to accomplish and removes the need to call WriteEndTag in their example.
This behavior can be verified easily. If you remove the self-closing tag from a Visual Studio Silverlight Web's *.html test page and add the explictly closed element, the behavior will manifest itself.
PS - Chrome and Firefox will also not load the Object tag if you provide a param element with an empty value. For example: <param name="onerror" value="" />