title: Insert Data into SQL table using Javascript and ASP.NET
body: <p>Im using Microsoft Visual Studio 2012 as platform and i have created Web Forms Project
  i have created data base file "SimpleDB.mdf" inside his "Table" folder i added new table called "Table" which has two columns - id and Name(string).What im trying is to insert string data into Name column of this table while calling server side function from javascript function.</p>
  
  <p>This is the aspx.cs code</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.Data.SqlClient;
  using System.Web.Services;
  
  namespace ProjectWWW
  {
      public partial class WebForm1 : System.Web.UI.Page
      {
          [WebMethod]
          public static string InsertData(string ID){
              string source = "Data Source=(LocalDB)\v11.0;Integrated Security=True;Connect Timeout=30";
              SqlConnection con = new SqlConnection(source); 
              {
  
                 SqlCommand cmd = new SqlCommand("Insert into Table(Name) values('" + ID + "')", con);
                  {
                      con.Open();
                      cmd.ExecuteNonQuery();
                      return "True";
                  }
              }
          }
  }
  </code></pre>
  
  <p>and this is the aspx code</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="ProjectWWW.WebForm1" %&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;   
      &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
      &lt;script&gt;
          function CallMethod() {
              PageMethods.InsertData("hello", CallSuccess, CallError);
          }
  
          function CallSuccess(res) {
              alert(res);
          }
  
          function CallError() {
              alert('Error');
          }
      &lt;/script&gt;
  &lt;/head&gt;
  
      &lt;body&gt;
          &lt;header&gt;        
          &lt;/header&gt;       
          &lt;div class="table"  id="div1" &gt; &lt;/div&gt;                      
          &lt;form id="Form1" runat="server"&gt;
              &lt;asp:Button id="b1" Text="Submit" runat="server" onclientclick="CallMethod();return false;"/&gt;
              &lt;asp:ScriptManager enablepagemethods="true" id="ScriptManager1" runat="server"&gt;&lt;/asp:ScriptManager&gt;
          &lt;/form&gt; 
  
      &lt;/body&gt;
  
  
     &lt;/html&gt;
  </code></pre>
  
  <p>So basically im expecting when the button submit is clicked the Table Column "Name" will be filled with "Hello" but nothing happens and the column stays empty(NULL)</p>