title: Uncaught Reference Error: function is not defined (ASP.NET)
body: <p>I'm teaching myself how to work with ASP.NET, and I'm trying to call a C# function in a JS function in my .aspx file.</p>
  
  <p>Here's my JS section:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
          function Run() {
          alert("Running!")
          var ranking = parseInt(document.getElementById("rank").value);
          var collsize = parseInt(document.getElementById("size").value);
          var collsafety = 
             parseInt(document.getElementById("safety").value);
          var best = PageMethods.Survey(ranking, collsize, collsafety);
          document.write(best);
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>The signature of the C# function (it's embedded in the .aspx file like the JS function):</p>
  
  <pre><code>&lt;script language="c#"&gt;
      [System.Web.Services.WebMethod]
      public static string Survey(int ranking, int collsize, int 
         collsafety) {
         ....
      }
  </code></pre>
  
  <p>The exact error message is: Uncaught ReferenceError: PageMethods.Survey is not defined.</p>
  
  <p>I'm calling the Run method with a button using onclick. I know the method is entered, because the first alert happens. However, when I try calling Survey, I get the error.</p>
  
  <p>I've already read a couple of answers, like this: <a href="https://stackoverflow.com/questions/13854712/jquery-pagemethod-saying-the-method-does-not-exist">jquery PageMethod saying the method does not exist</a>, but the suggested AJAX didn't work either. I also read this: <a href="https://www.codeproject.com/Questions/561226/errorpluspageMethodplusisplusundefined" rel="nofollow noreferrer">https://www.codeproject.com/Questions/561226/errorpluspageMethodplusisplusundefined</a> but I can't see what I'm not doing right...</p>