title: call asp.net web forms code behind using ajax
body: <p>I am working on this example scenario using ASP.NET web forms technology and jquery ajax:
  on change event on input text element, there is ajax request must send to function in code behind in asp.net page (Login.aspx/GetDoublicate) to check if email is exist in database or not and return true or false.
  my code:</p>
  
  <pre><code>        &lt;form id=&quot;form1&quot; runat=&quot;server&quot;&gt;
  &lt;div&gt;
  
      &lt;table style=&quot;width:100%;&quot; dir=&quot;rtl&quot;&gt;
          &lt;tr&gt;
              &lt;td class=&quot;auto-style1&quot;&gt;user name&lt;/td&gt;
              &lt;td class=&quot;auto-style1&quot;&gt;
                  &lt;input id=&quot;Text1&quot; type=&quot;text&quot; /&gt;&lt;/td&gt;
              &lt;td class=&quot;auto-style1&quot;&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class=&quot;auto-style1&quot;&gt;password&lt;/td&gt;
              &lt;td class=&quot;auto-style1&quot;&gt;
                  &lt;input id=&quot;Password1&quot; type=&quot;password&quot; /&gt;&lt;/td&gt;
              &lt;td class=&quot;auto-style1&quot;&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td class=&quot;auto-style1&quot;&gt;
                  confirm password&lt;/td&gt;
              &lt;td class=&quot;auto-style1&quot;&gt;
                  &lt;input id=&quot;Password2&quot; type=&quot;password&quot; /&gt;&lt;/td&gt;
              &lt;td class=&quot;auto-style1&quot;&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  email&lt;/td&gt;
              &lt;td&gt;
                  &lt;input id=&quot;Text2&quot; runat=&quot;server&quot; type=&quot;email&quot; /&gt;&lt;/td&gt;
    
              &lt;td&gt;&amp;nbsp;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  birth&lt;/td&gt;
              &lt;td&gt;
                  &lt;input id=&quot;Text3&quot; type=&quot;date&quot; /&gt;&lt;/td&gt;
              &lt;td&gt;&amp;nbsp;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;input id=&quot;Button1&quot; type=&quot;submit&quot; value=&quot;Subscripe&quot; /&gt;&lt;/td&gt;
              &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;td&gt;&amp;nbsp;&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/table&gt;
  
  &lt;/div&gt;
              &lt;/form&gt;
      
      
  
  
  
  
  &lt;div id=&quot;fffg&quot;&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>ajax request code</p>
  <pre><code> &lt;script&gt;
  
  
          $(document).ready(function () {
              $('#Text2').change(function () {
  
                  $.ajax({
                      type: &quot;GET&quot;,
                      url: &quot;Login.aspx/GetDoublicate&quot;,
                      'data': {&quot;email&quot;:$('#Text2').val() },
                      //contentType: &quot;application/json; charset=utf-8&quot;,
                      dataType: &quot;text&quot;,
                      success: function (response) {
                          console.log(response);
                      }
                  });
                  
  
              })
  
          })
          
  
      &lt;/script&gt;
  </code></pre>
  <p>Login.aspx page code behind:</p>
  <pre><code>  public bool GetDoublicate()
          {
  
  
              SqlConnection con = new SqlConnection(connectionString);
              con.Open();
              string sqltext = &quot;select id from CoAuthor where email='&quot; + Request.Params[&quot;email&quot;] + &quot;'&quot;;
              SqlCommand cmd = new SqlCommand(sqltext, con);
              string x = cmd.ExecuteScalar().ToString();
                        con.Close();
              if (string.IsNullOrEmpty(x))
              {
                  return true;
              }
              else return false;
  
  
  
  
          }
  </code></pre>
  <p>after that I get this:
  <a href="https://i.stack.imgur.com/0Wlix.png" rel="nofollow noreferrer">result</a></p>
  <p>and after log the response using console I get my page whole elements printed not only true or false that is meaning the function I need not called successfully.</p>
  <p>I tried to use WebMethod decorate but same fail result noting that I need to get data from DB which static method can't do that.</p>
  <p>I tried to use update panel and put hidden ASP button inside thus when (change event occurs on Text2 ) I clicked the hidden button using jquery .click method but also I can't get any result.</p>
  <p>thanks in advance for all.</p>