title: To set the value to a (textbox) server control using jquery ajax
body: <p>In the below mentioned code, I am able to set the value attained from ajax call only if I am using the HTML controls(button and text). If I am using asp server controls like button, I am not getting any output from ajax call even if I use the button as server control and text box as normal HTML control.  Thanks in Advance.</p>
  
  <p><strong>AjaxCall.aspx</strong></p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AjaxCall.aspx.cs" Inherits="SampleLogin.AjaxCall" %&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;Ajax Call&lt;/title&gt;
      &lt;script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;
          $(document).ready(function () {
      // $('#&lt;%= btnAjax.ClientID%&gt;').click(function () {     // If i use this iam not getting any response
              $('#submit').click(function () {
                  alert("clicked");
                  $.ajax({
                      type: "POST",
                      url: "AjaxCall.aspx/HelloWorld",
                      data: "{}",
                      contentType: "application/json",
                      dataType: "json",
                      success: function (msg) {
  
                          alert(msg.d);
                          $("#Result").val(msg.d);
                      }
                  });
              });
          });
    &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div&gt;
          &lt;input type="button" value="click" id="submit"  /&gt;
          &lt;asp:Button ID="btnAjax" runat="server" Text="GetVal" /&gt;
          &lt;input type="text" ID="Result" runat="server"&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>AjaxCall.aspx.cs Code:</strong></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.Web.Services;
  using System.Web.Script.Services;
  namespace SampleLogin
  {
      public partial class AjaxCall : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
          }
          [WebMethod(EnableSession = false)]
          public static string HelloWorld()
          {
              return "Hello";
          }
      }
  }
  </code></pre>