473,569 Members | 2,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Do cumentText = 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.Na vigate("about:b lank")', 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 40994
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:blan k". 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.OpenNe w() 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(obje ct sender, EventArgs e)
{
webBrowser1.Nav igate("about:bl ank");
webBrowser1.Doc ument.Write("He llo World!");
}

private void button1_Click(o bject sender, EventArgs e)
{
webBrowser1.Doc ument.OpenNew(t rue);
webBrowser1.Doc ument.Write("Go odbye 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
2759
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 but some default HTML. I want to copy the document and modify it before saving it to disk. So, I clone the document like this:
2
13942
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 the contents of the WebBrowser before I show the next page, they're appended one after the other. I've got some really simple code:
9
3795
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
5564
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 another web page in a new window and then closes it. I was able to control this action by detecting the 'NewWindow' event and opening the webpage in my...
12
6340
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 of course it's thrown up a whole host of new issues... I'm generating a multi page printable document in HTML from my app, and displaying it in a...
2
7185
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 the page to complete, then fills in the form. Next I want it to submit the form or after getting focus of the submit button, keys.enter. I've tried...
11
2809
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
11991
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 the WebBrowser control is sending. Effectively, my code would be the web server and the WebBrowser control would be the web client. All the...
2
4282
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, so if I need to elaborate on something please ask for it. We have a UserControl with a WebBrowser on it. This UserControl is instantiated a few...
0
7694
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7921
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7964
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2107
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.