title: How to call an ASP.NET WebMethod in a UserControl (.ascx)
body: <p>Is it possible to place a WebMethod in an ascx.cs file (for a UserControl)  and then call it from client-side jQuery code?</p>
  
  <p>For some reasons I can't place the WebMethod code in an .asmx or .aspx file.</p>
  
  <p>Example: In ArticleList.ascx.cs I have the following code:</p>
  
  <pre><code>[WebMethod]
  public static string HelloWorld()
  {
      return "helloWorld";
  }
  </code></pre>
  
  <p>In ArticleList.ascx file there I have the call to the WebMethod as follows:</p>
  
  <pre><code>$.ajax({
              type: "POST",
              contentType: "application/json; charset=utf-8",
              data: "{}",
              dataFilter: function(data)//makes it work with 2.0 or 3.5 .net
              {
                  var msg;
                  if (typeof (JSON) !== 'undefined' &amp;&amp;
                  typeof (JSON.parse) === 'function')
                      msg = JSON.parse(data);
                  else
                      msg = eval('(' + data + ')');
                  if (msg.hasOwnProperty('d'))
                      return msg.d;
                  else
                      return msg;
              },
              url: "ArticleList.ascx/HelloWorld",
              success: function(msg) {
                  alert(msg);
              }
          });
  </code></pre>
  
  <p>and the error from firebug is:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;This type of page is not served.&lt;/title&gt;
  </code></pre>
  
  <p><strong>How can I sucessfully call the server-side WebMethod from my client-side jQuery code?</strong></p>