Welcome Guest Search | Active Topics | Sign In | Register

EO.WebControl LoadHTML() fails when WebControl instantiated by code Options
Mr Binary
Posted: Thursday, April 23, 2015 12:45:33 PM
Rank: Newbie
Groups: Member

Joined: 4/23/2015
Posts: 5
I have been beating my head on the wall for over 2 weeks now. I am convinced that this is a major bug in the control and I would like to know how to resolve it. Here is my ridiculously simple function and the value returned by GetHtml() is always empty. NOTE: I should not have to be forced to use "LoadUrl()" or "LoadUrlAndWait()". I already have the HTML source so it makes sense to load it using LoadHtml().

As an experiment, I did create a temp file and saved my sample HTML and then used "LoadUrl" and LoadUrlAndWait()" and both failed. No matter which approach I take, all I ever get is a blank control.



HERE'S MY CODE:

private void LoadSampleHtml()
{

EO.WebBrowser.WinForm.WebControl ctl = new EO.WebBrowser.WinForm.WebControl();

ctl.WebView = new EO.WebBrowser.WebView();

ctl.Location = new Point(0, 0);
ctl.Height = this.Height;
ctl.Width = this.Width;


ctl.WebView.LoadHtml("<html><body>hello world!</body></html>");

MessageBox.Show("Length of content = " + ctl.WebView.GetHtml().Length, "Debug EO.WebControl");

}
eo_support
Posted: Thursday, April 23, 2015 2:04:00 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi,

This will certainly be empty. The WebView is not ready until it's fully initialized. In order for the WebView to be initialized, you have to place it in a container (for example, a Form), show that Form and waits until it to finishes. For example, you can use code like this:

ctrl.WebView.LoadHtml(your_html).WaitOne();

Note that the above code can only be called AFTER the container has been initialized (for example, after the control is placed in the form and the form's Load event has already been fired). You do not have to use LoadUrl or LoadUrlAndWait, but you MUST Wait since first, the WebView must finishes initializing before it can do anything else, second, even after it has finished initializing, LoadHtml is not instant (for example, if the HTML contains an external resource such as an image, then it will go to a remote server to load the image). So you must wait until it's done before you call GetHtml.

Hope this helps.

Thanks!
Mr Binary
Posted: Thursday, April 23, 2015 2:18:11 PM
Rank: Newbie
Groups: Member

Joined: 4/23/2015
Posts: 5
Thanks for your reply.

I spent more time today reading and re-reading the fine print in the documentation regarding the WebView class and how it requires an object handle when instantiated in code. Between your suggestion and making sure I use the WebView::Create(IntPtr handle) function properly, I FINALLY have things working.

I guess the problem was attributed to something between my chair and the keyboard :)

If I close a tab thereby releasing the tab resources, must I first call the WebView.Destroy() method or will that be looked after automatically when the tab goes out of scope?

Thanks again.
eo_support
Posted: Thursday, April 23, 2015 2:27:11 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,083
Hi,

No. Generally you do not need to call Create or Destroy yourself. In "normal" situation when everything is chained correctly (for example, when you place a WebControl inside a Form and attach a WebView to the WebControl), the WebView's Create and Destroy will be automatically called. The exception is when you create WebView manually/dynamically. However as soon as the WebView is placed inside somewhere (which is essentially what WebView.Create does), then the chain will be connected and you no longer need to call Destroy explicitly.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.