chrisbray
asked on
How can I stop WebBrowser control from ignoring setting DocumentText values?
Hi Guys,
I have a WinForms user control that contains a WebBrowser which is used to edit HTML, and it used to work perfectly. Lately a number of users have reported that it does not display the HTML assigned to it, and this proves consistently to be the case. I am not yet certain whether the issue relates to the OS (32 vs 64 bit, XP or Windows 7) or whether it relates to a security update, but I do know that it used to work a treat and now the WebBrowser stays blank. As far as I am aware nothing has changed in the control code, and this seems to be confirmed by source control.
I have seen many mentions of this issue and suggestions for resolutions on the web and have tried every one I have found, but still nothing!
Here is the basic code that initialises the WebBrowser:
Here is how the bodytext is set:
Any suggestions as to how I might get this working again?
I have a WinForms user control that contains a WebBrowser which is used to edit HTML, and it used to work perfectly. Lately a number of users have reported that it does not display the HTML assigned to it, and this proves consistently to be the case. I am not yet certain whether the issue relates to the OS (32 vs 64 bit, XP or Windows 7) or whether it relates to a security update, but I do know that it used to work a treat and now the WebBrowser stays blank. As far as I am aware nothing has changed in the control code, and this seems to be confirmed by source control.
I have seen many mentions of this issue and suggestions for resolutions on the web and have tried every one I have found, but still nothing!
Here is the basic code that initialises the WebBrowser:
// Web Browser
webBrowserBody.DocumentText = string.Empty;
if (webBrowserBody.Document != null)
{
webBrowserBody.Document.Click += WebBrowserBodyDocumentClick;
webBrowserBody.Document.Focusing += WebBrowserBodyDocumentFocusing;
webBrowserBody.Document.ExecCommand("EditMode", false, null);
webBrowserBody.Document.ExecCommand("LiveResize", false, null);
}
webBrowserBody.AllowNavigation = false;
webBrowserBody.AllowWebBrowserDrop = false;
webBrowserBody.IsWebBrowserContextMenuEnabled = false;
webBrowserBody.ScriptErrorsSuppressed = true;
Here is how the bodytext is set:
public override string Text
{
get { return webBrowserBody.DocumentText; }
set { webBrowserBody.DocumentText = value; }
}
Here is an example of the HTML retrieved from a database that is being assigned using the getter:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18928"></HEAD>
<BODY><FONT size=2 face=Arial>
<P>You received a new telephone message at %%MessageTime%% on
%%MessageDate%%</P>
<HR>
<BR>
<P><STRONG>Caller: </STRONG>%%Caller%%<BR><STRONG>Company:</STRONG>
%%CallerCompany%%<STRONG><BR>Telephone:
</STRONG>%%CallerTelephone%%<BR><STRONG>Email:</STRONG> %%CallerEmail%%</P>
<P><STRONG>Message:</STRONG><BR>%%TelephoneMessage%%</P>
<P>
<HR>
<P></P>
<P>%%User%%<BR>%%CompanyName%%<BR>%%CompanyMailingAddress%%<BR>%%CompanyWebInfo%%</FONT><BR></P></BODY></HTML>
We know that the HTML is valid and works, because we can assign it to an Outlook email and it works perfectly...Any suggestions as to how I might get this working again?
ASKER
Hi Bob,
Hmm... that made no difference on my 64 bit machine, and so far appears to work on 32 bit XP.
Hmm... that made no difference on my 64 bit machine, and so far appears to work on 32 bit XP.
Also, I have IE 9 installed...9.0.8112.16421
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The answer was found based on a snippet posted by a third party.
Thanks as always to TheLearnedOne who always makes every effort to help.
Thanks as always to TheLearnedOne who always makes every effort to help.
Open in new window