Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
West Wind WebSurge - Rest Client and Http Load Testing for Windows

Missing PageMethods on an MS AJAX Page?


:P
On this page:

You ever have one of those days when just nothing wants to go right? A couple of days ago I was working on my session code for ASP.NET Connections. One of my sessions is on Dealing with Long Running Requests and one of the examples uses AJAX to offload the processing to messaging engine and optionally a separate process/machine. I've had this demo around for some time and originally I built it using Microsoft AJAX Beta 2 or one of the release candidates.

So I dusted off the old demo and sat down to update it for the RTM version which should have been pretty quick. The first part was getting a Web.config file that actually has all the MS AJAX settings in them. The original Web.config had the beta settings so I thought the easiest way to do this was to create another project that is all set up for MS AJAX and then copy that web.config into the current project (after renaming the old one) and then simply migrating my actual configuration settings ( ConnectionStrings, AppSettings, and one handler) over to the new web.config.

I also had to tweak a number of replaces for $() syntax to $get() and a couple of changes in one of the client side controls used in the sample's JavaScript code. That's where I thought it would end.

Well it didn't. The sample uses JSON callbacks using PageMethods, which saw some changes late in the MS AJAX cycle. PageMethods were made static so they no longer ran in the context of the page at all (which kind of defeats the whole purpose of PageMethods in the first place - the old feature set allowed for access to the controls of the page and full POST data). Again so had to make some adjustments to the code to change to static methods and make sure that each of the methods actually was stateless and didn't use any of the form's objects (like the MessageManager). Again no big deal.

But at that point the page still would not work. Whenever I'd run the page, I'd get a JavaScript errors saying that PageMethods is not defined. Quickly checking the network trace with FireBug confirmed that the script resource that normally contains the AJAX JSON proxy never got created.

I checked:

  • Methods marked as [WebMethod]
  • Web Methods are static
  • ScriptManager on page
  • EnablePageMethods set on the script manager


No luck. I checked, re-checked my settings but no matter what I tried it just... would... not... work. I even went so far as to create a new page dropped a script manager on it, created a couple of WebMethods and called them from client script to make sure I wasn't doing something wrong and sure enough that worked just fine. It's just in the particular page that it wouldn't work.

Eventually - after about an hour of screwing around with this - I just created a Web Service and called that instead and that worked immediately. I honestly don't know what was wrong with that page if anything. I even called a friend of mine to check out the page with GotoMeeting (in case I couldn't see the forest for the trees 'ya know - wouldn't be the first time) but he didn't see anything either.

So... anybody ever seen this before? PageMethods not working on a page failing to send the proxy code to the client?

In the end I suppose that's a good thing anyway. PageMethods became pretty much useless anyway when they became static in RTM. There's really no benefit for using them (other than keeping your code encapsulated in the Page which is questionable to begin with) and it actually made the sample a bit cleaner. The message service checking and processing code now all runs in the service class which is easier to demonstrate separately anyway - once you find it buried in the APP_CODE directory...

Posted in ASP.NET  Microsoft AJAX  

The Voices of Reason


 

fran
September 14, 2007

# re: Missing PageMethods on an MS AJAX Page?

maybe you missed this in the web.config:

<system.web>
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx"
type="Microsoft.Web.Script.Services.ScriptHandlerFactory"
validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
</system.web>

Jeff
September 14, 2007

# re: Missing PageMethods on an MS AJAX Page?

Two things that have tripped me up are not including the EnablePageMethods="true" in the asp:ScriptManager and the other was caching, so I had to do a clean solution and rebuild everything.

Jay Kimble
September 14, 2007

# re: Missing PageMethods on an MS AJAX Page?

Rick,

As someone already mentioned, the ScriptManager EnablePageMethods attribute.

Something else I have run into is that you now also have to mark the method with the ScriptMethod attribute.

Jay Kimble

PS. if you wanna send me the code I can probably get it working for ya...

Wessam Zeidan
September 14, 2007

# re: Missing PageMethods on an MS AJAX Page?

Ran into the exact same issue, and couldn't solve it too. I had to use a webservice, although I wanted that functionality in 1 page only, which made sense to use PageMethods.

Johan Sassner
September 14, 2007

# re: Missing PageMethods on an MS AJAX Page?

Hi.
I also had problems with PageMethods, not noticing any changes in the code in the PageMethod method. So every time i made a change, i had to clean the solution and rebuild, just as the other guy said earlier.

J. Johnson
September 14, 2007

# re: Missing PageMethods on an MS AJAX Page?

I have had this exact problem numerous times on different projects. This issue can also occur when you are changing the method name or signature that you are using as your PageMethod. Once you verify that all of the properties, etc, are set, the number one cause that I have found for this weirdness is caching. Once you clean the cache, it works just fine.

One note about PageMethod goodness. Generally, if some functionality will be accessed by multiple pages in the site, then you would use the web service route; otherwise using a PageMethod is preferable. For one, it reduces your application’s security footprint and provides a level modularity to your code.

Hope this help.

J. Johnson

Rick Strahl
September 14, 2007

# re: Missing PageMethods on an MS AJAX Page?

Thanks all...

Just to clarify I did have EnablePageMethods=True on the ScriptManager. And I don't think caching was the issue because I saw the behavior both in IE and FireFox plus I reloaded IIS several times.

But it's interesting to hear that others have seen this behavior and so I don't feel like a complete dolt <s>...

Grewal
September 14, 2007

# re: Missing PageMethods on an MS AJAX Page?

Is your page methods inside the user control? I had the same issues, but putting the methods in the code behind of aspx kind of addressed this issue in my case.

Grewal

Yuriy
September 15, 2007

# re: Missing PageMethods on an MS AJAX Page?

Hello Rick,
I also had the same problem with PageMethods, try to add service reference to <asp:ScriptManager>.
<Services>
            <asp:ServiceReference Path="~/EcmService.asmx" />
</Services>


Also in service create at least one method with [WebMethod]
attribute, then try to use PageMethod. In my case it helps.

ILog
September 15, 2007

# re: Missing PageMethods on an MS AJAX Page?

Hello Rick,

I saw "PageMethods is undefined" error when my WebMethod was inside user control (even declared as static). Similar problem was inside master page. But in aspx it worked.

In some cases another attribute may help:
[System.Web.Script.Services.ScriptMethod]


Igor

Rick Strahl
September 15, 2007

# re: Missing PageMethods on an MS AJAX Page?

Thanks all for the feedback. I've tried all of the above except trying to add a separate script reference to another service which may or may not have worked. At this point I moved the code to a separate service and that has worked fine - so problem solved.

But it's definitely disconcerting to see that there are a issues with PageMethods not working in some scenarios. It doesn't sound like all the reports here are operator error like I was suspecting of myself <g>..

Mark Kemper
September 24, 2007

# re: Missing PageMethods on an MS AJAX Page?


My Page Method works perfectly in development environment, however I cannot for the life of me get in to work in a hosting environment.

Mark

Mark Taylor
September 27, 2007

# re: Missing PageMethods on an MS AJAX Page?

PageMethods will be available every time if you put the function in the aspx instead of the code-behind:

<script language="C#" runat="server">

[WebMethod]
public static int Add(int num1, int num2)
{
return num1 + num2;
}

</script>


Whats weird is if you put the function in the code-behind, the proxy will be generated sometimes, and other times not.

- Mark

sascha
October 08, 2007

# re: Missing PageMethods on an MS AJAX Page?

my god... same problem here. when i place my code in code-behinde, pagemethods is undefined... putting the method in aspx everything works fine... lol!
anyway, as already was said due to the static-only character of the pagemethods i need to get rid of using pagemethods... some things were better in "atlas".

Naveed
November 22, 2007

# re: Missing PageMethods on an MS AJAX Page?

Solution:

I have to go through a lot of pain to get pagemethods working.

Here are things to check

1. Static Method should be in actual page (content). It will not work if method is in User Control or Master page.

2. Set ContentManager property "EnablePageMethods" to true.

Mark Kemper
November 26, 2007

# re: Missing PageMethods on an MS AJAX Page?

All my page methods woes were solved by using a script service instead. I throughly recommend it to anyone using page methods.

See

http://xsation.blogspot.com/2007/11/forget-page-methods-move-on-to-script.html

For the hello world of the script service.

Mark

andrija11
December 17, 2007

# re: Missing PageMethods on an MS AJAX Page?

Naveed, thx for info, I didn't know PageMethods can not be used in master page

Tim Erwin
December 27, 2007

# re: Missing PageMethods on an MS AJAX Page?

Rick,

I was able to get it to work by using something like the following - it wasn't working for me until I used the form tag:

<form runat="server">

<asp:scriptmanager runat="server" EnablePageMethods="true" />

<script language="C#" runat="server">

[WebMethod]
public static void test( )
{

}

</script>

</form>

michael
January 09, 2008

# re: Missing PageMethods on an MS AJAX Page?

Post is a bit old but in case others are still having problems (doesn't seem to be any different in VS 2008/3.5 framework).

Also had similar problems but only with MasterPage or user controls. As was suggested before putting the method on the main .aspx page seems to work. If you want to be able to call on all pages then put the method in a base page class. Should look something like:

public class MyBasePageClass : System.Web.UI.Page
{

[System.Web.Services.WebMethod(true)] // true if you're using Session
[System.Web.Script.Services.ScriptMethod(UseHttpGet = true)] // httpget isn't necessary but often a good idea 
public static string MyCommonWebMethod()
{
  return "howdy";
}

}


Of course you'll also need to EnablePageMethods in the ScriptManager.

Does seem a bit too difficult. But it is kinda handy when it works.

steve thomas
February 09, 2008

# re: Missing PageMethods on an MS AJAX Page?

I was having this same problem. I fixed it by stopping and starting IIS. really strange, as I had another page that worked just fine in the project.

Warren Connors
February 19, 2008

# re: Missing PageMethods on an MS AJAX Page?

I recently had problems with this. Seemed like the client-side proxy code was not being regenerated IAW code mods. Seems inconsistent on Visual Studio's part--things that seem to help sometimes (as noted in other posts): rebuild, bouncing IIS, clearing the browser cache, exiting VS and going back in--even one time it seemed like it was fixed after I rebooted my whole PC. (Might this be due to VS stubbornly (and buggily) holding on to the javascript that is in some temporary asp.net files?) This might help some people: Noticed that when I switched from executing the website within IIS to using the VS dev server that MOST of the suspected regen problems went away (as well as always doing rebuild rather than build). I had been following a procedure of developing web apps using IIS execution rather than the dev server after having in the past seen some inconsistencies with the dev server (stuff working ok under the dev server and then not when the app executes under IIS or vice-versa); now for AJAX development I do the reverse (use the dev server). Heavy Sigh.

Jason Gaylord
February 21, 2008

# re: Missing PageMethods on an MS AJAX Page?

Rick,

Is your webservice in page or is it in a master page or control? The way the event hooks up to the Script Manager, it must be in a page. I just discovered this same issue.

Jason

Rick Strahl
February 21, 2008

# re: Missing PageMethods on an MS AJAX Page?

It was in the page. But the page was sitting inside of a Master Page content control.

Gavin Clark
February 27, 2008

# re: Missing PageMethods on an MS AJAX Page?

I had the same problem, PageMethods proxy was not being built at all.

It was solved by a clean rebuild of the entire project.

Some kind of VS caching issue?

Toby Kraft
March 05, 2008

# re: Missing PageMethods on an MS AJAX Page?

Rick,
Oh this stuff gets frustrating sometimes.
I had a default.aspx page that did a Server.Transfer to another page that I wanted to call a PageMethod from. Kept getting the PageMethod is undefined error or it couldn't find the method. Checked Event Log and saw "Unknown web method" errors, huh?
After quite some time I moved the method to the Default page, not the page where it's called and it sorta worked for a while.
Then I realized that maybe the Server.Transfer was contributing to the problem and changed that to a Response.Redirect and voila - it works reliably now! With the method on the ASPX page or in code-behind.
Fortunately, the sample here
http://www.asp.net/AJAX/Documentation/Live/tutorials/ExposingWebServicesToAJAXTutorial.aspx
does work and helped me keep the faith that it really does work and the problem was in my code.

Q
March 26, 2008

# re: Missing PageMethods on an MS AJAX Page?

Toby,

switching the Server.Transfer from my first screen to the 2nd one was the only thing that seemed to work for me. Guess you can't use the server transfer when the target page uses page methods...

Thanks!

Ben
March 30, 2008

# re: Missing PageMethods on an MS AJAX Page?

Yes...! I just found the same issue.. server transfer was the culprit... should be documented

Mats
April 17, 2008

# re: Missing PageMethods on an MS AJAX Page?

Hi Rick!

I just encountered this problem as well, it's related to the autogenerated proxy scripts being cached as far as I can understand. What I wonder is: On my production server, I have content expiration enabled and .js are cached at client, will this be a problem once I've deployed a new version of a page containing a changed Page method. Will clients not download the new clientscript files due to the content expiration or will ASP.NET regenerate the scripts. Have you got any clue?

Thanks for a great blog!

/Mats

Rick Strahl
April 17, 2008

# re: Missing PageMethods on an MS AJAX Page?

@Mats - pretty sure it wasn't caching for me at the time and even if it was client caching - either the proxy is there or not, to the browser it would still be available.

THere's some bug in the codepath it looks like based on the decriptions above that is causing the script reference inclusion to be omitted by ScriptManager it seems.

Svetlana Shelkova
April 22, 2008

# re: Missing PageMethods on an MS AJAX Page?

Absolutely nothing helps! PageMethods javascript is not being generated when running Web Project, but works fine from within a Web Site. I’ve tried both Visual Studio Development Server and IIS Web Server.

Marco
June 11, 2008

# re: Missing PageMethods on an MS AJAX Page?

I am having the same problem when using a Control object. I created my own GridView object to display dynamic reports and I wanted to embed some Ajax to manage the report (i.e. send db calls to the server to remove/manage/edit rows). I tried creating the ScriptManager on my page and passing it into the control, I also included my JS file in the control. Everything gets displayed on the page fine, but when I act on a row I get the PageMethods is undefined. I found some other code on the internet talking about using a WebService, which I am a little confused about, but I also found some blog from a MS dude with this quote:

"Hi,

No, you can't define the PageMethod inside a control. It must be defined in a page.

When the EnabledPageMethod property of the ScriptManager instance on the page is set to true, it'll inject script proxy for each web method defined in the page.

And the script proxy can't be generated if it's defined in a control. "

Sounds like a major design flaw in .net Ajax extensions.

Why is it that everytime I find an enhancement I think may be cool and easy to use in .Net it always ends up being way more complicated than I ever imagined?

Tim MCCurdy
June 11, 2008

# re: Missing PageMethods on an MS AJAX Page?

Yes, this happens to me all the time. Basically you just need to stop your site and restart it. I think the PageMethods are getting cached by ASP.NET in the Application somewhere and it doesn't always "recompile" the PageMethods.

If I am running on my Dev box, I just stop the running instance. Also, when I deploy, I try to make sure to restart the site.

Eralper
July 16, 2008

# re: Missing PageMethods on an MS AJAX Page?

Hello Rick,

One simple reason that might be forgotten can be if inline scripts are used in the aspx page the script tag should be defined as runat="server"
Methods also required with WebMethod attribute
So the aspx page itself must also import the Namespace="System.Web.Services" on the page declaration.

I have read somewhere that the server side scripts should not be written between HEAD html tags. But I'm not sure about it.

Thanks for your work on this web site. You share alot for developers.

Perley
August 28, 2008

# re: Missing PageMethods on an MS AJAX Page?

Same problem. Although I find if I perform an action on the page (causing a postback) the PageMethod will be found. Also even when the error occurs everything is showing fine in the source so that it should find the PageMehod with no problem. Wondering if I need to rebuild my development platform (old AJAX being found somewhere) or is it just a really starange quirk?

Trevor
August 28, 2008

# re: Missing PageMethods on an MS AJAX Page?

Sigh, same problem, get undefined error, have double checked all the problems, done IISReset, restared dev servers, brand new VS project with the very simplest of scenarios, same problem, undefined errror.

The proxies seem to be getting generated (although maybe they are old ones that are not getting rebuilt.)

I am on VS2008, 3.5 SP1

Greg Hodgson
September 10, 2008

# re: Missing PageMethods on an MS AJAX Page?

I'm not happy with replacing all my Server.Transfers with Response.Redirects.

From a customer point of view, it's a lot less professional a URL to see, and a lot longer, and a lot more error prone.

From a search engine point of view, a redirect is considered not a "real url" by things like Google, whereas a Server.Transfer is invisible to them. I've been using that for some time to make sure that google indexed all my dynamically generated product pages properly.

I'd rather ditch my new ajax widget than ditch server.Transfer, so I'm really hoping there is a better solution.

Anyone?

Mushtaq
September 26, 2008

# re: Missing PageMethods on an MS AJAX Page?

Hi all,
I am also facing the same problem, but in one of my test web application which I created earlier its work fine and even not a single time it give a error like "PageMethods undefined".
In both cases I m using the same scenario, a default page, a web user control and a helping js file. but one is going fine and other is going off ;(

Swilson
October 31, 2008

# re: Missing PageMethods on an MS AJAX Page?

Thanks for the tips guys, my local environment did not give me this error, however, dev and UAT server did. Not sure why, but the fix that worked for me was to move the static webmethod from the code-behind to the aspx file. Now the page works everywhere.

Cheers, Stu

gferreira
December 06, 2008

# re: Missing PageMethods on an MS AJAX Page?

Always this hapens

close the Visual Studio

Clear de temporary .net
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

Open the project/website again

and run.

James
December 10, 2008

# re: Missing PageMethods on an MS AJAX Page?

I was moving code from a page to a usercontrol that contained webmethods. I was able to access them through a web method on the new aspx page by declaring a new webmethod of the same name as the user control and then calling the user control web method as the return.


[WebMethod]
public static string ReallyCoolUserControlWebMethod(string x, string y)
{
return ASP.your_user_control.ReallyCoolUserControlWebMethod(x, y);
}

(ASP.your_user_control is a registered usercontrol on page)

Jim Wilson
January 15, 2009

# re: Missing PageMethods on an MS AJAX Page?

I know this is an old post but I figured I'd chime in incase anyone else came across this page while searching for the answer to this problem.

Clearing the cache (in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files) worked for me! Thank you to the posters who suggested this.

Steve
January 27, 2009

# re: Missing PageMethods on an MS AJAX Page?

if you are using cookieless sessions - the generated script proxy will set the page path to '/pagename.aspx' which will break the PageMethod.

To fix you must reset the path to the page method right before you call your method.

e.g.,

PageMethods.set_path('pagename.aspx') // without the leading '/' which is in the generated proxy
PageMethods.MyMethod(params[], OnSuccess, OnFail);

Steve
January 27, 2009

# re: Missing PageMethods on an MS AJAX Page?

continuing the previous issue with cookieless sessions

This error will present itself as a 401 error:

Sys.Net.WebServiceFailedException: The server method 'MyMethod' failed with the following error: System.InvalidOperationException--Authentication failed.

Stefan
February 21, 2009

# re: Missing PageMethods on an MS AJAX Page?

My problem (I luckily found the solution) was related to a IIS configuration I made for a Web Deployment Project (avoiding copying these aspx placeholder files). See here: http://stackoverflow.com/questions/573193/asp-net-ajax-pagemethods-is-undefined-script-error-on-production-server-works

Kris
April 20, 2009

# re: Missing PageMethods on an MS AJAX Page?

Steve's comment fixed it for me:

if you are using cookieless sessions - the generated script proxy will set the page path to '/pagename.aspx' which will break the PageMethod.

To fix you must reset the path to the page method right before you call your method.

e.g.,

PageMethods.set_path('pagename.aspx') // without the leading '/' which is in the generated proxy

AlexandroRR
May 28, 2009

# re: Missing PageMethods on an MS AJAX Page?

.. I think that is the zero error: User error :)
I don't know what I move, write or delete in my program, but when I restart over from zero the code, it works with the same stuff that I had work. Sadly, I was 3 hours late at work to find this...
And as u said, just have to:
• Methods marked as [WebMethod]
• Web Methods are static (Shared in VB)
• ScriptManager on page
• EnablePageMethods set to "True" the script manager

This is an helpful example:

http://geeks.ms/blogs/mrubino/archive/2008/12/18/serializar-deserializar-json-en-asp-net.aspx?CommentPosted=true


Regards from México!!!

John H
June 29, 2009

# re: Missing PageMethods on an MS AJAX Page?

Agggh! I spent about 4 hours beating my head against the wall with this. Definitely a caching issue. I find that if I change anything in my web method in my code behind the page method is still returing the results from the last time it worked. I even tried create a new web method in my code behind and found that was not visible as a page method method when I debugged.

The fix was to do a Clean Solution then a Rebuild Solution. Thanks for the suggestions for this...thought I was loosing my mind.

Also, I found no difference whether the code for the web method was in the .aspx file or the code behind. Same issue for me...VS is caching the page method and won't see any changes to it until I clean and rebuild. Crappy way to develop but I'll have to live with it I guess.

Ameet Shah
July 13, 2009

# re: Missing PageMethods on an MS AJAX Page?

Steves Comment of setting the service path
PageMethods.set_path('pagename.aspx')

works well for the Master Page case as well.
In case of MasterPage the service path sets to the default page of the site.
You should set it to the page where your server side page methods are.

fernando
August 05, 2009

# re: Missing PageMethods on an MS AJAX Page?

HI, I can access PageMethods, but inside it I tried to do this : grid.databind(); and I found that I cant access the grid from here.
anybody knows why?

thanks!

Tyler
August 11, 2009

# re: Missing PageMethods on an MS AJAX Page?

Thank you Steve!

I agree with Ameet, two posts above. I'm using a Master Page and setting the service path FINALLY fixed my problem.

Thank you!

Mark Schultheiss
August 21, 2009

# re: Missing PageMethods on an MS AJAX Page?

One more tidbit on the stack of this old one, bit of jQuery mixed in here for the Ajax part:
I had:
...
$("#testAuto").autocomplete(window.location.pathname + "/NewProcedure.aspx/MyPageMethod", {
...

and changed it to:
...
$("#testAuto").autocomplete( "NewProcedure.aspx/MyPageMethod", {
...

did not recieve the unknown issue after that.

jono
August 23, 2009

# re: Missing PageMethods on an MS AJAX Page?

Hi,
I'm having the same problem, its really fustrating because you can't tell if the problem is related to something you've just done, or something you did before it cached. Is there anyway to ensure that caching doesn't become an issue. Highly annoying!!

If developers are using page methods heavily in their projects how the heck do they go about debugging their code if they constantly run into this awful mess?!?

# re: Missing PageMethods on an MS AJAX Page?

I had been facing this problem when I tried to return a DataTable. This error
was keeping on occuring what ever.

Here's the solution.

Uncomment these lines in web.config.

<jsonSerialization maxJsonLength="500">

<converters>

<add name="DataSetConverter" type=&
quot;Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter,
Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&
quot;/>

<add name="DataRowConverter" type=&
quot;Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter,
Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&
quot;/>


<add name="DataTableConverter" type=&
quot;Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter,
Microsoft.Web.Preview, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35&
quot;/>


</converters>

</jsonSerialization>
Read More

<A href="http://muruganad.com/ASP.NET/ajax_PageMethods_System_InvalidOperationException.html">http://muruganad.com/ASP.NET/ajax_PageMethods_System_InvalidOperationException.html</a>

Thanks!
<a href="http://muruganad.com">Murugan Andezuthu Dharmaratnam</a>

Jeremy
December 09, 2009

# re: Missing PageMethods on an MS AJAX Page?

This is old, but I'm going to add my solution here to possibly help save someone time.


Adding "using System.Web.Services;" to my masterpage worked for me, even though my scriptmanager had EnablePageMethods="true" on the same masterpage.

Aaron
December 10, 2009

# re: Missing PageMethods on an MS AJAX Page?

Had the same problem. I dug through the generated code and found the _staticInstance after the PageMethods..... frustrating!!!!!!!!!!!

So I call my page methods like this.

PageMethods._staticInstance.[FunctionName]

Karthik
January 14, 2010

# re: Missing PageMethods on an MS AJAX Page?

seems like the PageMethods only work on .apsx pages.Hope some one finds the solution or a work around with masterpages and usercontrols

Serge
April 06, 2010

# re: Missing PageMethods on an MS AJAX Page?

Make sure you static web method isn't declared inside a MasterPage, in which case they will not be resolved and you will end up with this error. Just another reason to use a simple service.

Amar Nath Satrawala
April 11, 2010

# re: Missing PageMethods on an MS AJAX Page?

place static method in content page

Mark
April 24, 2010

# re: Missing PageMethods on an MS AJAX Page?

I cam across something similar recently, on a login page (had no authentication). once I configured web.config to allow anonymous access to the page vola!! it worked. your webservice may be already be granted anonymous access.

Paul
April 27, 2010

# re: Missing PageMethods on an MS AJAX Page?

So annoying. I had to remove my code out of a user control to an aspx page. Once I did that it worked.

omid
May 13, 2010

# re: Missing PageMethods on an MS AJAX Page?

ur post really helped, Thanks Dr. Hood River.

Shinyhat
August 06, 2010

# re: Missing PageMethods on an MS AJAX Page?

I had this exact issue and it turned out to be caused by the PROTECTION LEVEL on my WebMethod. It was marked private and it didn't work. Changed that to public and it starting working fine.

JK
August 13, 2010

# re: Missing PageMethods on an MS AJAX Page?

Hi,
This is very strange problem and its been more than 1 and half day, but I am still unable to solve it, I tried everything which is written above in the comments suggested be different people.

In my case the wiered part is, my code works fine in IE and PageMethods call take place properly and do the work as expecte, but when EXACTLY same code I try to run through Firefox, it always call OnFailed method of PageMethods call.

In same web app I have more webmethods and pagemethods calls on different pages and they all run fine on IE and Firefox, only this specific page is giving this problem.

I am still spending time on it to get rid off this problem. :(

Regards

Janessa
September 15, 2010

# re: Missing PageMethods on an MS AJAX Page?

I am now having this issue. Has there been any resolution?

Rick Strahl
September 15, 2010

# re: Missing PageMethods on an MS AJAX Page?

@Janessa - I haven't seen this issue in a while anymore especially in ASP.NET 4.0.

Eric
December 08, 2010

# re: Missing PageMethods on an MS AJAX Page?

Check for reserved javascript keywords in your WebMethod parameters (in code-behind). I had the following webmethod:

C#...
[WebMethod]
public static void DoSomething(bool delete)
{
...
}

javascript:
PageMethods.DoSomething(true);

.NET creates a javascript proxy for the webmethod. As you can see, my webmethod parameter name was "delete". This isn't reserved in C#, but is in Javascript. Renaming this parameter solved the problem.

Howard
January 14, 2011

# re: Missing PageMethods on an MS AJAX Page?

I spent a couple days fighting this. It is working find in other forms in my project but could not resolve it in going forward. I just took this approach instead.

http://www.codeproject.com/KB/aspnet/CallCodeBehindByJS.aspx

This worked great first time and I'm not looking back! The server side code doesn't have to be static which is also a plus. No more PageMethods.

Jamie Plenderleith
February 07, 2011

# re: Missing PageMethods on an MS AJAX Page?

I've found PageMethods to be so very sketchy when setting them up.
When they're working they work great. But randomly when trying to set them up they'll just refuse to work. Rarely do I see the PageMethods javascript get produced correctly first time

Ironman_E
April 06, 2011

# re: Missing PageMethods on an MS AJAX Page?

The issue arises when placing the WebMethod in your master page and not in the main page. For some reason ToolKitScriptManager doesn't recognize the webmethods on the master page. You'll have to move it to the main page or create a base class which all your pages inherit from.

Anderson
September 23, 2011

# re: Missing PageMethods on an MS AJAX Page?

So, in my case I was trying use it within an user control. I moved the code out of the user control and it worked!

Julie LErman
January 06, 2014

# re: Missing PageMethods on an MS AJAX Page?

Thought you'd get a laugh out of me hitting this 6+ years later. I am shoving some jquery & knockoutjs into a 10 year old asp.net webforms page (hold over while we wait for a new app) and spent 2 hours wondering what I was doing wrong. When I finally saw the ref to the calling page in the chrome debugger I googled my way to this blog post. :)

Johan
November 10, 2016

# re: Missing PageMethods on an MS AJAX Page?

Hi!
I realize this is an old blogpost but for anyone else having this problem: try putting the code-behind inline in the actual aspx page - this works for me.

<script language="C#" runat="server"> 
 
            [System.Web.Services.WebMethod]
            public static void GetDetails(string Id)
            {
                // Do stuff here.
            }
 
        </script> 
        <script type="text/javascript">
            function GetDetails(Id) {
                PageMethods.GetDetails(id);
            }
            GetDetails(42);
</script>

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024