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 6 and 6 and type the answer here:
  • Post
  • Is there any time frame, for the next refresh of Beta 1?

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

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

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

    --Brian

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

  • 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

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

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

  • 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

           Else

               Return True

           End If

       End Function

    I am calling this method by a javascript :-

    function Availability()

    {

       var uid=document.getElementById('ctl00_ContentPlaceHolder1_txtJukeboxId').value;

       if(uid=="")

       {

           alert('Please enter Jukebox Id!!!!!!');

           return false;

        }

        PageMethods.CheckAvailability(userName,OnComplete);

        return false;

    }

    function OnComplete(result)

    {

       var lblMessage = document.getElementById('lblMessage');

       if(result)

       {

           lblMessage.innerText="The Id is available";

       }

       else

       {

           lblMessage.innerText = "The Id is unavailable";

       }

    }

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

  • Add a property  EnablePageMethods="true" into the ScriptManager

Page 2 of 2 (26 items) 12