firstly i have searched a lot and all topics seems to be C# : call or invoke a JavaScript function but i want to do the opposite , i want to create a function on C# and also on JavaScript and i want the JavaScript function call the C# function and retrieve it`s data , it seems like a good questions . The problem is that i have no knowledge on web and i do not know how does it work , but i tried a sample :
Created a class :
public interface IFoo
{
string Bar { get; set; }
}
public class Foo : IFoo
{
public string Bar { get; set; }
}
Then
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public IFoo CreateFoo()
{
return new Foo() { Bar = "somevalue" };
}
public string Bar(IFoo foo)
{
return foo.Bar;
}
}
And Javascript Code :
<script type="text/javascript" language="javascript" >
function Callme(){
alert('Js function start . keep pressing OK')
var foo = external.CreateFoo();
alert(foo.Bar);
foo.Bar = "qwer";
alert(external.Bar(foo));
}
</script>
I get Error from the webbrowser control :
Error : "external" is null or not an object
But the javascript is not showing anything , please guide me if i missed something.