Call Managed C# Method from JavaScript Code

After searching quite long to find a way to call a C# Method from any JavaScript Code which is hostet in a WinForms Webbrowser Control, I found this one here:

C# Code
public class ScriptManager
Form mForm;

public ScriptManager(Form form)
mForm= form;
public void MethodToCallFromScript()

public class MyForm : Form
private Webbrowser mBrowserCtrl;

public MyForm()


mBrowserCtrl = new Webbrowser();
mBrowserCtrl.ObjectForScripting= new ScriptManager(this);


public void DoSomething(){}


JavaScript Code
function HandleSomething()


Trackbacks & Pingbacks


  1. * kashif says:

    Does this window.external.MethodToCallFromScript() works similarly if created in VB.NET? Thank you, even this code is very helpful

    | Reply Posted 10 years ago
  2. * globetech says:

    Yes it should work, since this is part of the .net Framework, but it won’t work in .net Compact Framework.

    | Reply Posted 10 years ago
  3. * kashif says:

    thanks for the prompt reply. how would i make a class com visible? thanks again.

    | Reply Posted 10 years ago
  4. * braintech says:

    Imports System.Runtime.InteropServices

    <ComVisible(False)> _
    Class SampleClass
    End Class

    for more details have a look at:

    | Reply Posted 10 years ago

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: