Call External Function from WebBrowser

I'm developing an application for Pocket PC 2003 using Visual Studio 2005. Within the application I have a WebBrowser control and I am writing html to it. I would like to be able to call a function from within the webbrowser. Here's my sample code:

private void Form1_Load(object sender, EventArgs e)
{
String html = "<html><body><form>";
html += "<input type=\"Button\" onClick=\"window.external.Test()\" value=\"Call Function\" />";
html += "</body></html>";
webBrowser.DocumentText = html;
}

public void Test()
{
MessageBox.Show("Hello from Browser");
}

I would like to be able to click on the html button and call the Test() function. Also, I've tried to select "Make assembly COM-visible" under the project properties, but it is greyed out so I can not select it. I'm sure I'm doing something stupid, but I've searched for hours with no solutions. Thanks.



Answer this question

Call External Function from WebBrowser

  • Idaho

    NETCF does not support hosting so you can't make assembly COM-visible and you can't call function from the browser. Not to mention it’s very complicated and indirect way to do it. Consider getting rid of the browser, adding button instead and calling required function. You can add buttons and other controls dynamically if that’s what you’re after.



  • Call External Function from WebBrowser