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

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]:


public class MyWebService : WebService{


   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 {



   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">



   public static string MyMethod() {

              return "MyMethod Called";



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

Comments (26)

  1. asorcinelli says:

    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?

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

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

  4. dimitrod says:


    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?

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

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

  7. rstrahl says:

    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.

  8. dimitrod says:

    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.

  9. 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!

  10. MrSmersh says:

    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…

  11. jlchereau says:

    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

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

  13. Colin says:

    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.

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

  15. mteper says:


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

  16. dave_s says:

    Is there any time frame, for the next refresh of Beta 1?

  17. I have written a few posts on PageMethods (most notably here and here &hellip; there are probably a few

  18. Iniciamos hace unos dias la migraci&oacute;n del CTP ATLAS a la versi&oacute;n Beta, tuvimos varios problemas

  19. BrianHearn says:

    This Microsoft Gold Partner will be a world of hurt for everything we were using ATLAS for if PageMethods must be static. Please reconsider this hugely impacting change. Thank you.


  20. Delay's Blog says:

    I previously blogged a sample demonstrating how to use the AJAX Control Toolkit’s dynamic population

  21. corporreal says:

    Have any decisions been made regarding this issue?  My project would also be severely crippled by switching to Beta 1 due to the PageMethods changes

  22. Oggi mi sono un p&ograve; divertito nell&#39;utilizzo della release delle Asp.Net Ajax Extensions, focalizzandomi

  23. I’ve been searching for some content I finally found on a blog here, but need a litlte more help. I am

  24. kapilsanchihar says:

    If am writing following web method in my code behind file :-

    <System.Web.Script.Services.ScriptMethod()> <System.Web.Services.WebMethod()> Public Function CheckAvailability(ByVal UserName As String) As Boolean

           _commandString = String.Format("Select UserName from jukebox.login where UserName='{0}’", txtJukeboxId.Text)

           _myDataReader = ManageDB.GetDataReader(_commandString)

           If _myDataReader.Read Then

               Return False


               Return True

           End If

       End Function

    I am calling this method by a javascript :-

    function Availability()


       var uid=document.getElementById(‘ctl00_ContentPlaceHolder1_txtJukeboxId’).value;



           alert(‘Please enter Jukebox Id!!!!!!’);

           return false;



        return false;


    function OnComplete(result)


       var lblMessage = document.getElementById(‘lblMessage’);



           lblMessage.innerText="The Id is available";




           lblMessage.innerText = "The Id is unavailable";



    now I am getting runtime error as "pagemethods not defined" in javascript.

  25. blbirajdar says:

    Add a property  EnablePageMethods="true" into the ScriptManager

Skip to main content