473,395 Members | 1,763 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Clearing a WebBrowser control

In .NET 2.0, how do I clear the contents of a web browser control?

I'm using a WebBrowser control in a Windows Form app to display strings
genrated by my application and formatted as HTML--I'm not using it to do any
actual web browsing.

I use 'webBrowser1.DocumentText = myText' to load an HTML string into the
control. But I can't clear that text when I want to load a new string into
the control.

I've tried 'webBrowser1.Navigate("about:blank")', and that doesn't seem to
work. I've looked for articles about using the WebBrowser control as an HTML
renderer, but I've had no luck.

Any articles out there? Any suggestions on how to clear the control? Thanks
in advance.

David Veeneman
Foresight Systems

Jan 27 '07 #1
1 40939
I found my answer. Don't use the DocumentText property to write text to a
WebBrowser control. Instead, use the Document object.

1) Initialize the document object by navigating it to "about:blank". This is
required, as otherwise the Document property will be null.

2) Use the Document.Write() method to write text to the WebBrowser control.

3) Use the Document.OpenNew() method to clear the control, after which more
text can be written.

Here's a siimple demo. Create a Windows Forms app and put a WebBrowser
control and a Button on Form 1. Create event handlers for the Form1_Load and
button1_Click events. Then add the following code to the event handlers:

private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("about:blank");
webBrowser1.Document.Write("Hello World!");
}

private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Document.OpenNew(true);
webBrowser1.Document.Write("Goodbye World!");
}

The demo will open with "Hello World!" showing in the WebBrowser control.
When you click the button, the text will be replaced by "Goodbye World!"

David Veeneman
Foresight Systems
Jan 27 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Charles Law | last post by:
Sorry for the cross post, but I'm not sure who is best placed to answer this one. This is the most bizarre behaviour of MSHTML and streams. I have a WebBrowser control that contains nothing...
2
by: jhattersley | last post by:
Hi Folks, Wonder if you can help... All I'm trying to do is load a couple of simple HTML pages (in memory) into the WebBrowser control, one after the other. I don't seem to be able to clear...
9
by: ASP .NET Newbie | last post by:
How can I run a WebBrowser control using ASP.NET/VB.NET? I know I can use the WebClient to get the page data, but I need to be able to use the WebBrowser (AxWebBrowser)? Thanks, Chad
1
by: Tuong | last post by:
I have a situation where i have a form that contains a webbrowser control. With this I was able to implement an application that can browse websites. One particular website i visited opens up...
12
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
2
by: jasonhartsoe | last post by:
I'm using Visual Studio 2005 Team Edition....using visual basic. I'm trying to use the webbrowser control. In the webbrowser control I have it got to a page where there is a form. It waits for...
11
by: Anil Gupte | last post by:
....and how do I insert one into my form? I used in VB 6.0 last, but cannot figure out where it is in .Net Thanx, -- Anil Gupte www.keeninc.net www.icinema.com
4
by: Steve Richter | last post by:
I would like to build an HTML stream as a string and have the WebBrowser control render that HTML. Then on PostBack, or whatever it is called, I would like my code to be the one that receives what...
2
by: Jeroen | last post by:
We are experiencing a tuff-to-debug problem ever since we introduced a WebBrowser control into our failry large application. I'm not sure if the problem description below contains enough details,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.