0

I am currently working on a project where I am using a WebBrowser control as an editor. I have design mode turned on and it seems to be working. The issue im having is when I try to save the Document and load another it pops up the "This document has been modified." message. What I am trying to do is as simple as this

if (frontPage)
{
    frontPage = false;
    frontContent = webEditor.DocumentText;
    webEditor.DocumentText = backContent;
}
else
{
    frontPage = true;
    backContent = webEditor.DocumentText;
    webEditor.DocumentText = frontContent;
}

Like I said everytime I enter some text and run this code it just pops up a message saying its been modified and asks if I want to save. How can I get around this?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
thecaptain0220
  • 2,098
  • 5
  • 30
  • 51

7 Answers7

2

You should create the following function:

void ChangeAllowWebBrowserDrop() { webBrowser.AllowWebBrowserDrop = !webBrowser.AllowWebBrowserDrop; }

It should be called every time before you change DocumentText.

sashaeve
  • 9,387
  • 10
  • 48
  • 61
1

I have solved this problem so:

browser.Document.Write(string.Empty);  
browser.DocumentText="Your html code"; 

This is from this link: http://social.msdn.microsoft.com/Forums/vstudio/en-US/3a9c1965-8559-4972-95e1-da0e86cf87bb/webbrowser-strange-problem

wertyk
  • 410
  • 10
  • 30
1

You could set

BodyHtml.  

Like this:

string newHTMLString="some html";
webBrowser1.Document.Body.InnerHtml = newHTMLString;

Worked for me .

Alex
  • 768
  • 1
  • 5
  • 13
1

You should create the following function:

void ChangeAllowWebBrowserDrop() {
    webBrowser.AllowWebBrowserDrop = !webBrowser.AllowWebBrowserDrop;
}

It should be called every time before you change DocumentText.

sjngm
  • 12,423
  • 14
  • 84
  • 114
1

better solution is to write empty string before you actually assign your html code: WebBrowser1.Document.Write(string.Empty);
WebBrowser1.DocumentText = "your code";

Zviadi
  • 731
  • 2
  • 8
  • 19
0

Try this webEditor.ScriptErrorsSuppressed = true;

Make sure you have disabled Script Debugging in IE in case you've turned it on.

Keith Adler
  • 20,880
  • 28
  • 119
  • 189
0

The way Windows Forms load a document stream (used by the DocumentText property) is to navigate away to about:blank, which triggers the document modified message, then load the stream in its DocumentComplete event handler.

Since you already have a document, you can skip the navigation and load the stream into the existing document directly via its IPersistStreamInit interface like Windows Forms does in its DocumentComplete event handler.

Sheng Jiang 蒋晟
  • 15,125
  • 2
  • 28
  • 46