title: Error "PageMethods is undefined" in Webpart for Sharepoint 2010
body: <p>I am getting PageMethods is not defined javascript error in my sharepoint 2010 webpart.
  Basically, i have created webpart which displays the google map. upon clicking the marker of the google map, i want to call the server side event. I have implemented the jquery for the same. I am using the PageMethods to call the server method. Below is the code which i fetched from some blog site only. I have also addeed the scriptmanager tag on my page with the EnablePageMethods attribute set to true.</p>
  
  <p>Script block:</p>
  
  <pre><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 () {
          // Initialization                            
          $("#ajax_loading_image").hide();
          // mousemove event
          $().mousemove(function (e) {
              window.status = e.pageX + ', ' + e.pageY;
          });
          // hook up the click event            
          $("#execute_page_method").click(function () {
  
              $("#message").text("I'm working...");
              $("#ajax_loading_image").show("fast");
              $("#execute_page_method").hide("fast");
  
              // Call some page method...
              PageMethods.ProperMethodName("string", function (result, userContext, methodName) {
  
                  $("#ajax_loading_image").hide("slow");
                  $("#execute_page_method").show("slow");
  
                  if (result.Success == true) {
                      alert("true");
                      $("body").css("background", "#CAFFD8");
                  }
                  else {
                      $("body").css("background", "#CAFFFF");
                  }
  
                  $("#message").text("This took me " + result.Time + " milliseconds...  ");
  
              });
              return false;
          });
      });
  &lt;/script&gt;
  
  &lt;div&gt;
      &lt;a id="execute_page_method" href="http://jquery.com/"&gt;Click!&lt;/a&gt;
  &lt;/div&gt;
  
  Code Behind events:
  public class MethodReturnedValue
          {
              public int Time { get; set; }
              public bool Success { get; set; }
          }
  
          [WebMethod(true)]
          public static MethodReturnedValue ProperMethodName(string param)
          {
              Random random = new Random();
              MethodReturnedValue retVal = new MethodReturnedValue();
              retVal.Time = random.Next(5000);
              Thread.Sleep(retVal.Time);
              if (random.Next() % 2 == 0)
              {
                  retVal.Success = true; ;
              }
              else
              {
                  retVal.Success = false;
              }
              return retVal;
          }
  </code></pre>
  
  <p>The same code is works fine in my asp.net appication and not working in my sharepoint application.
  Can anyone please help me out in this.</p>