title: How I Call Master Page Method Using Jquery Ajax
body: <p>I can't call <code>[WebMethod]</code> from <code>Master Page</code> using <code>Jquery Ajax</code>.</p>
  
  <p>I am getting the error as follows:</p>
  
  <blockquote>
    <p>GetCompletionList (forbidden)</p>
  </blockquote>
  
  <p>I have the following code in <code>Jquery</code> on <code>markup</code> of <strong>Default.aspx</strong> webpage with <strong>Master page</strong>:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function ShowImage() {
          document.getElementById('txSearch')
              .style.backgroundImage = 'url(/aspnet/img/snake_transparent.gif)';
  
          document.getElementById('txSearch')
              .style.backgroundRepeat = 'no-repeat';
  
          document.getElementById('txSearch')
              .style.backgroundPosition = 'right';
      }
  
      function HideImage() {
          document.getElementById('txSearch')
              .style.backgroundImage = 'none';
      }
  
      $(function () {
          $("[id$=txSearch]").autocomplete({
              source: function (request, response) {
                  $.ajax({
                      url: '&lt;%=ResolveUrl("Mymasterpage.master/GetCompletionList") %&gt;',
                      data: "{ 'prefixText': '" + request.term + "'}",
                      dataType: "json",
                      type: "POST",
                      contentType: "application/json; charset=utf-8",
                      success: function (data) {
                          response($.map(data.d, function (item) {
                              return {
                                  label: item.toString,
                                  val: item.toString
                              }
                          }))
                      },
                      error: function (response) {
                          alert(response.responseText);
                      },
                      failure: function (response) {
                          alert(response.responseText);
                      }
                  });
              },
              select: function (e, i) {
                  $("[id$=hfSearch]").val(i.item.val);
              },
              minLength: 1
          });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>In <em>Code Behind</em> of <strong>Master Page</strong> <strong>Mymasterpage.master.cs</strong> I have this:</p>
  
  <pre><code>[ScriptMethod()]
  [WebMethod]
  public static List&lt;string&gt; GetCompletionList(string prefixText)
  {
      using (OdbcConnection con =
          new OdbcConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString))
      {
          using (OdbcCommand com =
              new OdbcCommand())
          {
              com.CommandText = " SELECT ";
              com.CommandText += "    sName ";
              com.CommandText += " FROM ";
              com.CommandText += "    `tbl_name` ";
              com.CommandText += " WHERE ";
              com.CommandText += "    sName LIKE CONCAT('%',?,'%'); ";                
  
              com.Parameters.AddWithValue("param1", prefixText);
              com.Connection = con;
              con.Open();
  
              List&lt;string&gt; countryNames = new List&lt;string&gt;();
  
              using (OdbcDataReader sdr = com.ExecuteReader())
              {
                  while (sdr.Read())
                  {
                      countryNames.Add(sdr["sName"].ToString());
                  }
              }
              con.Close();
              return countryNames;
          }
      }
  }
  </code></pre>
  
  <p>Why is it so ? </p>
  
  <p>How to solve it ?</p>
  
  <p>Thanks</p>