From Atlas to ASP.NET AJAX: Page Methods
Atlas supported page methods: A functionality to embed web service methods into .aspx pages and consume them with JavaScript. For instance, if you had the following method:
[WebMethod]
string sayHello() {
return “Helloâ€;
}
—you could consume this method from JavaScript using the PageMethods.sayHello() call.
With ASP.NET AJAX, this has changed a bit. You have to change WebMethod to ScriptMethod, but you also have to edit the ScriptManager control to explicitly support page method calls:
<asp:ScriptManager id=â€asm†runat=â€server†EnablePageMethods=â€true†/>
Otherwise, ASP.NET AJAX no longer creates the necessary JavaScript proxy for the web service calls.
Also, you have to change the method a bit:
It additionally needs the ScriptMethod attribute
It must be declared as static
Here is one possible way:
[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string sayHello() {
return “Helloâ€;
}
(Part of the Atlas to ASP.NET AJAX Migration series.)
Read more at nospam@example.com (Christian)