title: Javascript : call a C# function
body: <p>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 :</p>
  
  <p>Created a class :</p>
  
  <pre><code>public interface IFoo
  {
      string Bar { get; set; }
  }
  
  public class Foo : IFoo
  {
      public string Bar { get; set; }
  }
  </code></pre>
  
  <p>Then</p>
  
  <pre><code>public partial class Form1 : Form
  {
      public Form1()
      {
          InitializeComponent();
  
      }
  
      public IFoo CreateFoo()
      {
          return new Foo() { Bar = "somevalue" };
      }
  
      public string Bar(IFoo foo)
      {
          return foo.Bar;
      }
  }
  </code></pre>
  
  <p>And Javascript Code :</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript" &gt;
  
  function Callme(){
  alert('Js function start . keep pressing OK')
  var foo = external.CreateFoo();
  alert(foo.Bar);
  foo.Bar = "qwer";
  alert(external.Bar(foo));
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I get Error from the webbrowser control :</p>
  
  <pre><code>Error : "external" is null or not an object
  </code></pre>
  
  <p>But the javascript is not showing anything , please guide me if i missed something.</p>