If you are getting PageMethods Is Undefined Error while using AJAX in ASP.NET or using a webservice than you need to check these things to resolve the issue
1. PageMethods needs to be static
[WebMethod] public static int MethodName() { }
2. Enable pageMethods in scriptManager
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"> </asp:ScriptManager>
3. add reference to script service in code behind
Add [Microsoft.Web.Script.Services.ScriptMethod] or [System.Web.Script.Services.ScriptService] in code behind below [WebMethod]
WebMethod] [Microsoft.Web.Script.Services.ScriptMethod] public static string GetRecords() { //DO something }
Hope this helps
If you like this post than join us or share
8 comments:
Add script manager attribute as EnablePartialRendering="true".
i'm using webusercontrol. i want to call C# function in this usercontrol, but the scriptmanager located in masterpage.
Thanks, I used to keep getting "PageMethods is undefined"... then i changed my method to be static and it works now :)
cheers!
god byrjun
I think there is a bracket missing in #3.
I wan to handle event arguments in the above webmethod. How can i handle paramater based web methods? Please help me
@Ramesh: Please refer Call Asp.Net WebService PageMethods Or WebMethod WIth Parameters Using JavaScript Or JQuery
No good
Post a Comment