Discussion:
WebBrowser in .NET 2.0: !DOCTYPE gets overwridden
(too old to reply)
Joubert Nel
2005-12-23 22:27:57 UTC
Permalink
Hi,

I have an XHTML document that I wish to display to the user in the .NET 2.0 WebBrowser control, and allow the user to edit it.

I got everything working beautifully but noticed that the control tampers with the !DOCTYPE definition.
Here is the XHTML that I pass to the WebBrowser control:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>HtmlEditor</title>
<style type="text/css">
BODY {font-family:Tahoma; font-size:10pt; color:#000000; font-weight:400; PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px}
</style>
</head>
<body>
</body>
</html>

As you can see, this is simply a template, giving the user a blank slate where they can now edit.

However, after the above snippet is loaded by the WebBrowser (I use the .Document.OpenNew(); and then .Document.Write(".....") methods) the !DOCTYPE is changed to:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

Does anybody know why this is happening, what the potential effects are, and how I can resolve?

Thanks

Joubert
Herfried K. Wagner [MVP]
2005-12-24 11:05:00 UTC
Permalink
Post by Joubert Nel
I have an XHTML document that I wish to display to the user
in the .NET 2.0 WebBrowser control, and allow the user to edit it.
I got everything working beautifully but noticed that the control
tampers with the !DOCTYPE definition.
I believe the problem is that IE doesn't support XHTML and treats it as
HTML.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
e_zverev
2006-01-17 18:11:02 UTC
Permalink
Post by Herfried K. Wagner [MVP]
I believe the problem is that IE doesn't support XHTML and treats it as
HTML.
Don't believe this :) IE supports XHTML 1.1

The problem is that IE does not support a single character before the
DOCTYPE declaration. In your case this is "<?xml version="1.0"
encoding="utf-8"?>
" instruction that spoils the whole thing.

Remove everything before DOCTYPE, even a comment would be enough for IE to
get ignorant to your DOCTYPE.

THE question to MS guys is: why'o'why is this so...fragile?!

Oh man, I've spent an hour to find it out. It ran me nuts.
--
Eugene U. Zverev,
Senior Programmer
Herfried K. Wagner [MVP]
2006-01-17 18:27:10 UTC
Permalink
Post by e_zverev
Post by Herfried K. Wagner [MVP]
I believe the problem is that IE doesn't support XHTML and treats it as
HTML.
Don't believe this :) IE supports XHTML 1.1
Not really. It supports XHTML 1.0/1.1 if it is provided as 'text/html' and
treats it as normal HTML. However, XHTML 1.1 is not indended to be made
available as 'text/html'. 'application/xhtml+xml' should be used as content
type for XHTML 1.1 documents instead.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Joubert Nel
2006-01-17 20:28:35 UTC
Permalink
Hello Eugene,

Some feedback inline.

Thanks
Joubert
Post by e_zverev
Post by Herfried K. Wagner [MVP]
I believe the problem is that IE doesn't support XHTML and treats it as
HTML.
Don't believe this :) IE supports XHTML 1.1
From what I can gather on both MS and other sites (for example
http://blogs.msdn.com/ie/archive/2005/09/15/467901.aspx) this is not the
case.

For example, try to actually load XHTML into IE and then do a View Source.
Note the changes it makes
Post by e_zverev
The problem is that IE does not support a single character before the
DOCTYPE declaration. In your case this is "<?xml version="1.0"
encoding="utf-8"?>
" instruction that spoils the whole thing.
Remove everything before DOCTYPE, even a comment would be enough for IE to
get ignorant to your DOCTYPE.
THE question to MS guys is: why'o'why is this so...fragile?!
Oh man, I've spent an hour to find it out. It ran me nuts.
--
Eugene U. Zverev,
Senior Programmer
Pavel Mikula
2009-11-26 09:34:28 UTC
Permalink
I believe this thread is closed already, but I've just came across the same issue.

WebBrowser.Document.Body.SetAttribute("contenteditable", "true")

instead of setting designMode property of DomDocument to "on" solves this issue for me

From http://www.developmentnow.com/g/30_2005_12_0_0_662936/WebBrowser-in-NET-2-0-DOCTYPE-gets-overwridden.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com/g/
Pavel Mikula
2009-11-26 09:44:49 UTC
Permalink
I've celebrated too early :( DocumentText property stopped working so document seemed to keep XHTML, but it doesn't

From http://www.developmentnow.com/g/30_2005_12_0_0_662936/WebBrowser-in-NET-2-0-DOCTYPE-gets-overwridden.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com/g/

Loading...