.Net WebBrowser.DocumentText没有改变! [英] .Net WebBrowser.DocumentText Isn't Changing!

查看:299
本文介绍了.Net WebBrowser.DocumentText没有改变!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的vb.net程序中,我使用web浏览器向用户显示HTML预览。我以前打过一台服务器来抓取HTML,然后返回一个异步线程,并引发一个事件,用我返回的HTML字符串填充WebBrowser.DocumentText。

In my vb.net program, I am using a webbrowser to show the user an HTML preview. I was previously hitting a server to grab the HTML, then returning on an asynchronous thread and raising an event to populate the WebBrowser.DocumentText with the HTML string I was returning.

现在,我设置它来获取客户端上的所有信息,而无需打开服务器,我正在尝试提交相同的事件。我注意到代码已经过去了,它的HTML字符串是正确的,但是当我尝试做的时候

Now I set it up to grab all of the information on the client, without ever having to hit the server, and I'm trying to raise the same event. I watch the code go through, and it has the HTML string correct and everything, but when I try to do

browser.DocumentText = _emailHTML

DocumentText的内容保留为< HTML>< / HTML>>

the contents of DocumentText remain as "<HTML></HTML>"

我只是想知道为什么没有设置DocumentText。任何人有任何建议吗?

I was just wondering why the DocumentText was not being set. Anyone have any suggestions?

推荐答案

请尝试以下操作:

Try the following:

browser.Navigate("about:blank");
HtmlDocument doc = browser.Document;
doc.Write(String.Empty);
browser.DocumentText = _emailHTML;

我发现 WebBrowser 控件通常需要初始化为 about:blank ,无论如何。在导航到不同类型的内容(如text / xml到text / html)之间需要完成相同的工作,因为渲染器是不同的(mshtml for text / html,其他文本/ xml文件)。

I've found that the WebBrowser control usually needs to be initialized to about:blank anyway. The same needs to be done between navigates to different types of content (like text/xml to text/html) because the renderer is different (mshtml for text/html, something else for text/xml).

(通过 http://geekswithblogs.net /paulwhitblog/archive/2005/12/12/62961.aspx

这篇关于.Net WebBrowser.DocumentText没有改变!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆