Home > ASP.NET security > From Atlas to ASP.NET AJAX: Page Methods

From Atlas to ASP.NET AJAX: Page Methods

April 4th, 2007

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)



BritneyIIII ASP.NET security , , , , ,

  1. No comments yet.
  1. No trackbacks yet.