PageMethods not defined despite copying example code
<p>On another forum someone complained that PageMethods are not defined. And someone provided an answer that said ... 'look, this is how you get them to work'. So I copied their code and tried it. I am still seeing PageMethods not defined.</p>

<p>The page looks like this:</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageMethods.aspx.cs" Inherits="PageMethods" %&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" &gt;
&lt;head runat="server"&gt;
&lt;title&gt;Untitled Page&lt;/title&gt;
&lt;/head&gt;
&lt;body onload="GetFromServer();"&gt;
&lt;form id="form1" runat="server"&gt;
&lt;asp:ScriptManager runat="server" ID="ScriptManager1" EnablePageMethods="true"&gt;&lt;/asp:ScriptManager&gt;
&lt;div&gt;

&lt;/div&gt;
&lt;/form&gt;
&lt;script type="text/javascript"&gt;
function GetFromServer()
{
PageMethods.GetHello(OnGetHelloComplete);
}
function OnGetHelloComplete(result, userContext, methodName)
{
alert("Result: " + result + "\n" +
"Context: " + userContext + "\n" +
"Method name: " + methodName);
}
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>And this is the code behind.</p>

<pre><code>using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Services;
using System.Web.Script.Services;
public partial class PageMethods : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string GetHello()
{
    return "Hello From Server!";
}
}
</code></pre>

<p>When you run the page a javascript error occurs - 'PageMethods' is not defined.</p>

<p>This is a .net 2.0 web site.</p>
