PageMethods not defined despite copying example code

Flexroro

New Member
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.The page looks like this:\[code\]<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageMethods.aspx.cs" Inherits="PageMethods" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"><title>Untitled Page</title></head><body onload="GetFromServer();"><form id="form1" runat="server"><asp:ScriptManager runat="server" ID="ScriptManager1" EnablePageMethods="true"></asp:ScriptManager><div></div></form><script type="text/javascript">function GetFromServer(){PageMethods.GetHello(OnGetHelloComplete);}function OnGetHelloComplete(result, userContext, methodName){alert("Result: " + result + "\n" +"Context: " + userContext + "\n" +"Method name: " + methodName);}</script></body></html>\[/code\]And this is the code behind.\[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\]When you run the page a javascript error occurs - 'PageMethods' is not defined.This is a .net 2.0 web site.
 
Back
Top