Atlas 1: Try not to use page methods

One of the easiest thing in Atlas is to use the
Page Method
feature. If you use Atlas on your web page say
Default.aspx, you can directly call public methods on Default.aspx
from javascript. Just put a [WebMethod] attribute on a public
method in Default.aspx and then you can them from Javascript using
PageMethods.MethodName().

public partial class _Default
: System.Web.UI.Page {
protected void Page_Load( object sender,
EventArgs e) { } [WebMethod]
public string DoSomething( string param)
{
return param; } }

On the client side you can call this method like this:

PageMethods.DoSomething(
Hi
, function (result) { alert(result); } );

Here’s the catch, Page method calls are always HTTP POST calls.
You can never make HTTP GET call to the Page methods but you can
make HTTP GET calls to Web service method. So, on later stage of
your project when you will need Http response caching in order to
save roundtrips, you will have to refactor all page methods to web
service methods and for this you will have to move all public
methods and related code from default.aspx to some web service. So,
try not to use Page methods from Day 1.

9 thoughts on “Atlas 1: Try not to use page methods”

  1. This is no longer true in ASP.NET AJAX RC 1.

    [WebMethod]

    [ScriptMethod(UseHttpGet=true)]

    public static string PageMethodTest(string name)

    {

    return String.Format(“Hello {0}”, name);

    }

    works absolutely fine and it can be in the code behind file (as opposed to inlining bug in Beta2).

  2. Shiva –

    How about in ascx files. Previously we had to use AJAXPro.Net in order to make this work in user controls. Is this functionality availble in Ajax.Net 1.0.

    Thanks for your response,

    Ben

Leave a Reply