Question

I am attempting to call a C# method on my winform from a page opened in a web browser control similar to this:

http://msdn.microsoft.com/en-us/library/system.windows.forms.webbrowser.objectforscripting%28v=vs.110%29.aspx

On my winform I have this method:

    public void Test(String message)
    {
        MessageBox.Show(message, "client code");
    }

and on my web page I am calling: window.external.Test('called from script code');

When I attempt to call this I get a javascript error: "invalid procedure call or argument"

However when I modify my form's method to take no parameter (like public void Test()) and accordingly make the javascript call without the parameter, it works without any issue. I only have the issue when I am attempting to pass parameters (which I need to do).

more info: I do have the following attributes on my form class:

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]

and I am assigning the ObjectForScripting:

webBrowser1.ObjectForScripting = this;

When debugging it does not appear to enter the forms method block.

I must be missing something simple.

Was it helpful?

Solution

Dumb mistake. I was evaluating that the function was not undefined as you normally would before calling a function from some other part of code. For some reason this evaluation was where the error was being raised, not the call itself (that was actually ok).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top