title: How to call a codebehind function using javascript?
body: <p>I'm trying to call this code behind function :</p>
  
  <pre><code>protected void Insert(object sender, EventArgs e)
          {
              blah blah blah code
              this.BindGrid();
          }
  </code></pre>
  
  <p>While in the .aspx file I've got my java function which looks like this:</p>
  
  <pre><code>&lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"&gt;&lt;/asp:ScriptManager&gt;
  &lt;asp:Button ID="Button2" runat="server" Text="Call Button Click" Style="display:none" OnClick="Insert" /&gt;
  &lt;asp:Button ID="btnAdd" runat="server" Text="Add" OnClientClick="return Validate();" Width="100" /&gt;
  
          &lt;script type="text/javascript"&gt;
                  function Validate()
                  {
                      var id = document.getElementById("txtStudentID").value;
                      Number(id);
                      var fn = document.getElementById("txtFirstName").value;
                      String(fn);
                      var ln = document.getElementById("txtLastName").value;
                      String(ln);
                      var cls = document.getElementById("txtClass").value;
                      String(cls);
                      var rn = document.getElementById("txtRollNumber").value;
                      Number(rn);
                      My code blah blah blah
                      document.getElementById("Button2").click();
                      PageMethods.Insert(onSuccessMethod, onFailMethod);
                  };
            &lt;/script&gt;
  </code></pre>
  
  <p>I need the Insert to work when I press the button add (the one that's visible).
  I'm not sure if my logic is correct or if there's a better way to it.
  It'd be much appreciated if someone knew hot can I call the Insert fonction from my javascript. I've tried a couple of stuff from google but none of them seem to work.
  thanks in advance</p>