Shawn Burke's Blog

Pushing the new stuff

Hint: Components that use Web Services with ASP.NET AJAX v1.0 Beta

Hint: Components that use Web Services with ASP.NET AJAX v1.0 Beta

  • Comments 26

Oh, something I forgot to put in the migration guide(s).

If you're calling any web service methods from client script, this has changes a little bit.

You now need to decorate those web services with [ScriptService]:

[Microsoft.Web.Script.Services.ScriptService]

public class MyWebService : WebService{

   [WebMethod]

   public void HelloWorld(){}

}

If you want to use Page Methods, they now need to be static, and have the ScriptMethod attribute:

public class MyPage : Page {

   [WebMethod]

   [Microsoft.Web.Script.Services.ScriptMethod]

   public static string MyMethod() {

              return "MyMethod Called";

    }

}

 UPDATE:  One thing I forgot to mention is that your page method can't be in codebehind (e.g. the above won't work) due to a bug in this first  AJAX release.  You need to put the method into your ASPX Page like so:

 <script runat="server">

[WebMethod]

   [Microsoft.Web.Script.Services.ScriptMethod]

   public static string MyMethod() {

              return "MyMethod Called";

    }

</script>

Accessing them via the Toolkit hasn't changed.  All the components that have ServiceMethod/ServicePath properties, just leave ServicePath blank, and specify the method (e.g. "MyMethod" or "HelloWorld" from above).

Leave a Comment
  • Please add 8 and 8 and type the answer here:
  • Post
  • How can i call a Page Method from Javascript? Before i use PageMethods.FUNCTION_NAME, now I always have an error.

    Is there another change in Beta 1?

  • Stamattina, fiducioso delle prove precedenti, ho aggiornato i miei progetti passando dalla CTP di Atlas...

  • Depends on the error you're getting.  The namespace may have changed - it should be into the docs somewhere.  We're not calling through Proxies (since we don't know the WebService/PageMethod ahead of time).

    Try Sys.Net.PageMethods.FunctionName(param)

  • Shawn,

    Now that Page Methods need to be static how can I access control values in these methods? For example in a PageMethod I need to iterate over dynamically generated controls in a PlaceHolder and return a string. Is this possible?

  • Right - thats definitely a problem.  They reason the AJAX team decided to make these methods static was so you could avoid page-lifecycle issues and subtleties, such as the inability to modify or access page state.  But it also stops you from doing the above.  

    The "right" way to do what you're talking about above is to write a simple control that implements ICallbackEventHandler.  If you look at ReorderList, you can see an example of this.

    I'm really not sure how to do it with a PageMethod, unfortunately.

  • Patrice et Fox vous l'a déjà annoncé hier : Une nouvelle version de Microsoft Ajax Extensions (nom de

  • That's really silly if you ask me. If all we can do is static methods anyway you might as well use an external Web Service and separate this data layer.

    Implement ICallbackHandler? You gotta be kidding. That interface is brain-dead <s>...

    ATLAS should provide this functionality in the way it worked in the previous builds even if it means that you can't update the page in anyway (ie. changes made to page content are are just 'thrown out'). That should allow getting around the life-cycle issues. It's updating that's problematic. Assigning state is pretty straight forward.

    But getting access to the control values is the key.

  • Agree with rstrahl. PageMethods are absolutely useless in the Beta1 - WebServices can do the same. One more thing I noticed is that a PageMethod has to be declared in the aspx file. If I declare it in the codebehind it doesn't work.

  • Yes - I called out the bug with the code behind above.  It's a known issue that's already been fixed in the Core tree.

    With respect to the static PageMethods, I'll transmit this feedback to the AJAX team.  I agree the utility of static page methods isn't great.  I'll re-raise the issue with them.  Thanks for the feedback!

  • Please do so...

    The static has bring me again to the old asp problem, I have the data on the server, but i need it on the client to do somenthing. A simple case I have a GridView I need the selected item in the client side to use on VirtualEarth to make a zoom... BTW the accordion control is better but still is not able to handle divs, again put VE on an pane...

  • Apparently a PageMethod cannot be accessed on the login page of a web site with forms autentication. Is this by design or is this a bug.

    Please post teh response to http://forums.asp.net/thread/1438911.aspx

  • いつもの投稿とは違い、今回は紹介と簡単な説明だけに留めておきたいと思います。(ただし、読みきれていない物もあります。) 理由としては、単純に私自身の時間が取れないからです。。。事実、一番最初に伝えようと思うのは2週間程前に見つけた投稿で、非常に面白く勉強になったのですが、細かな説明等を行う時間が無いままずるずると今日まで来てしまっていました。

  • Just adding my 2 cents here.  Aftering spending a while migrating to the beta version, we are now going to be rolling back to Atlas CTP.  This change to static methods has broken too much of our code.  I'm hopeful that this will get changed to allow for a non-static version and we will be able to upgrade with the next version; until then we will, unfortunately, remain on Atlas.

  • Hoy día iniciamos la migración de uno de nuestros aplicativos basados en Ajax, realmente bastante tedioso,...

  • +1

    The static requirement is a deal-breaker for us as well.

Page 1 of 2 (26 items) 12