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.

Published Friday, September 22, 2006 7:08 PM by omar
Filed under:

Comments

# MVP Award

Friday, November 03, 2006 11:55 PM by Omar AL Zabir (MVP)

I have been awarded MVP Award 2007 on Visual C# again. This is my second year. This time the gifts are...

# MVP Award

Saturday, November 04, 2006 12:04 AM by Omar AL Zabir - Most Versatile Personality (MVP)

I have been awarded MVP Award 2007 on Visual C# again. This is my second year. This time the gifts are

# ATLAS: Try not to use Page Methods

Tuesday, November 14, 2006 8:47 AM by DotNetKicks.com

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# re: Atlas 1: Try not to use page methods

Tuesday, November 14, 2006 8:58 AM by Rachit

To add more info about the PageMethods, in Beta 2, the PageMethods work only if you have placed the code in "in-line" page (in .aspx, not in .aspx.cs).

Check http://forums.asp.net/thread/1459613.aspx out for this bug.

Just my $0.02!

# Good site

Saturday, December 09, 2006 7:52 AM by Torrie Wilson in a thong

Torrie Wilson in a thong

http://torriewilson.cn.to

# re: Atlas 1: Try not to use page methods

Monday, December 18, 2006 10:36 AM by Shiva Shankar P

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).

# re: Atlas 1: Try not to use page methods

Tuesday, March 13, 2007 12:51 PM by Ben

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

# re: Atlas 1: Try not to use page methods

Monday, August 04, 2008 1:27 AM by sheryar nizar

USE page methods . they are really amazing. and avoid post back.and does your work

--

SHERYAR NIZAR

http://sheryar.net

Leave a Comment

(required) 
(required) 
(optional)
(required)