I am attempting to call a C# method on my winform from a page opened in a web browser control similar to this:
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.