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
Add script manager attribute as EnablePartialRendering="true".
ReplyDeletei'm using webusercontrol. i want to call C# function in this usercontrol, but the scriptmanager located in masterpage.
ReplyDeleteThanks, I used to keep getting "PageMethods is undefined"... then i changed my method to be static and it works now :)
ReplyDeletecheers!
god byrjun
ReplyDeleteI think there is a bracket missing in #3.
ReplyDeleteI wan to handle event arguments in the above webmethod. How can i handle paramater based web methods? Please help me
ReplyDelete@Ramesh: Please refer Call Asp.Net WebService PageMethods Or WebMethod WIth Parameters Using JavaScript Or JQuery
ReplyDeleteNo good
ReplyDelete