title: JSON postback to c# webmethod add literal control
body: <p>I'm learning about webmethods and posting back to them using JSON, I've got the following below, but it says it can't find the webmethod (404). Can't see where I'm going wrong, thanks.</p>
  
  <p>In the page javascript:</p>
  
  
  
  <pre class="lang-js prettyprint-override"><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"&gt;&lt;/script&gt;
         &lt;script type="text/javascript"&gt;
             $(document).ready(function () {
                 $(".FilterResults").click(function () {
                     var topic = $(".DropDownList1").val();
                     var number = $(".DropDownList2").val();
                     var month = $(".DropDownList3").val();
                     $.ajax({
                         type: "POST",
                         url: "filterresultshold.asmx/filterresults",
                         data: "{'args': '" + topic + "'}",
                         contentType: "application/json; charset=utf-8",
                         dataType: "json",
                         success: function (msg) {
                             // If you return something from the method, it can be accessed via msg.d                
                         }
                     });
  
                     // To prevent the postback
                     return false;
                 });
             });
  &lt;/script&gt; 
  </code></pre>
  
  <p>In the ascx:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>&lt;form id="form1" runat="server"&gt;
   &lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" /&gt;
      &lt;div&gt;
          &lt;asp:PlaceHolder ID="PlaceHolder1" runat="server"&gt;&lt;asp:Literal ID="Literal1" Text="Text to display" mode="PassThrough" runat="server" /&gt;&lt;/asp:PlaceHolder&gt;
          &lt;asp:DropDownList ID="DropDownList1" class="DropDownList1" runat="server"&gt;&lt;/asp:DropDownList&gt;
          &lt;asp:DropDownList ID="DropDownList2" class="DropDownList2" runat="server"&gt;&lt;/asp:DropDownList&gt;
          &lt;asp:DropDownList ID="DropDownList3" class="DropDownList3" runat="server"&gt;&lt;/asp:DropDownList&gt;
          &lt;asp:Button ID="FilterResults" class="FilterResults" runat="server" Text="Fill DropDownList" /&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>In the code behind:</p>
  
  
  
  <pre class="lang-cs prettyprint-override"><code>    using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Services;
  
  /// &lt;summary&gt;
  /// Summary description for filterresults
  /// &lt;/summary&gt;
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
  [System.Web.Script.Services.ScriptService]
  public class filterresultshold : System.Web.Services.WebService {
  
      [System.Web.Services.WebMethod]
      public void filterresults(string args)
      {
          string[] data = args.Trim().Split(',');
          string topic = data[0];
          string number = data[1];
          string month = data[2];
          string control = "&lt;umbraco:Macro alias='pdfarchivelist' runat='server' topic='" + topic + "' number='" + number + "' month='" + month + "'&gt;&lt;/umbraco:Macro&gt;";
          //LiteralControl literal = new LiteralControl(control);
          //PlaceHolder PlaceHolder1 = new PlaceHolder();
          //PlaceHolder1.Controls.Add(literal);
      }
  
  }
  </code></pre>
  
  <p>Then in the .ascx code behind:</p>
  
  <pre class="lang-cs prettyprint-override"><code>public partial class usercontrols_pdfarea : System.Web.UI.UserControl
  {
      protected void Page_Load(object sender, EventArgs e)
      {      
          if (!Page.IsPostBack)
          {
              // Populate Drops
              var rootNode = uQuery.GetRootNode();
              DropDownList1.Items.Add(new ListItem("SELEZIONA NUMERO"));
              DropDownList2.Items.Add(new ListItem("SELEZIONA MESE"));
              DropDownList3.Items.Add(new ListItem("SELEZIONA ARGOMENTO"));
  
              //display the password on the Gallery Folder in the media area
              var startMedia = uQuery.GetMediaByName("pdfs").FirstOrDefault();
              var DropList = rootNode.GetDescendantNodes().Where(x =&gt; x.NodeTypeAlias == "File");
  
              foreach (var item in startMedia.Children)
              {
                  DropDownList1.Items.Add(new ListItem(item.getProperty("number").Value.ToString())); //NUMBER
                  DropDownList2.Items.Add(new ListItem(item.getProperty("month").Value.ToString())); //MONTH
              }
  
              foreach (var item in startMedia.Children.Select(p =&gt; p.GetPropertyAsString("topic")).Distinct().ToList())
              {
                  DropDownList3.Items.Add(new ListItem(item.ToString()));
              }
          }
      }
  }
  </code></pre>