Welcome to MSDN Blogs Sign in | Join | Help

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

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

Published Saturday, October 21, 2006 6:50 AM by sburke

Comments

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

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?

Saturday, October 21, 2006 5:16 AM by asorcinelli

# AJAX Beta 1: problemi con la PageMethods

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

Saturday, October 21, 2006 7:19 AM by Alessandro Sorcinelli

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

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)

Saturday, October 21, 2006 10:50 AM by sburke

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

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?

Saturday, October 21, 2006 1:18 PM by dimitrod

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

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.

Saturday, October 21, 2006 6:24 PM by sburke

# Microsoft Ajax 1.0 (beta) et Microsoft Control Toolkit disponible (détail des changements)

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

Saturday, October 21, 2006 6:25 PM by Cyril 's Blog

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

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.

Sunday, October 22, 2006 6:33 AM by rstrahl

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

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.

Sunday, October 22, 2006 12:04 PM by dimitrod

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

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!

Sunday, October 22, 2006 12:56 PM by sburke

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

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

Monday, October 23, 2006 11:26 AM by MrSmersh

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

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

Tuesday, October 24, 2006 4:45 AM by jlchereau

# Microsoft "AJAX"(Atlas) のオススメ10月内投稿

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

Tuesday, October 24, 2006 5:48 AM by ナオキにASP.NET(仮)

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

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.

Tuesday, October 24, 2006 12:05 PM by Colin

# ASP.NET Ajax Beta 1: Cambios de la versi&amp;#243;n Atlas.

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

Tuesday, October 24, 2006 3:07 PM by Ivan Mostacero

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

+1

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

Tuesday, October 31, 2006 3:19 PM by mteper

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

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

Tuesday, October 31, 2006 8:28 PM by dave_s

# Thoughts on MS ASP.NET Ajax Extensions Beta and Preview CTP Beta and PageMethods...

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

Thursday, November 02, 2006 8:27 AM by Jay Kimble -- The Dev Theologian

# Atlas y la migración a la versión Beta.

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

Wednesday, November 08, 2006 6:42 PM by Roberto Hurtado

# Static PageMethods = show stopper

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

Wednesday, November 15, 2006 2:35 PM by BrianHearn

# Dynamic content made easy *redux* [How to: Use the new dynamic population support for Toolkit controls]

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

Friday, November 17, 2006 10:57 PM by Delay's Blog

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

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

Friday, December 29, 2006 9:34 AM by corporreal

# Cascading DropDownList [Method Error 500]

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

Thursday, January 25, 2007 12:13 PM by Mario Ferrante's Blog

# ModalPopupExtender and .asmx Web Service File

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

Thursday, February 22, 2007 6:07 PM by ASP.NET AJAX Forum Posts

# problem in using pagemethods with asp.net extensions 1.0

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.

Tuesday, March 06, 2007 4:11 AM by kapilsanchihar

# Using Web Services with the ASP.NET AJAX Extensions

Friday, April 06, 2007 11:02 AM by Cameron's Dungeon

# re: problem in using pagemethods with asp.net extensions 1.0

Add a property  EnablePageMethods="true" into the ScriptManager

Monday, November 19, 2007 4:08 AM by blbirajdar
Anonymous comments are disabled
 
Page view tracker