• Server Side
-It can only be defined on the ASPX page.
-Only public static methods can be used.
-Use webmethodattribute to mark
-Set the enablepagemethods attribute of scriptmanager to true.
• Client
-Access through pagemethods. methodname
Aspx < Form ID = " Form1 " Runat = " Server " >
< ASP: scriptmanager ID = " Scriptmanager1 " Runat = " Server " Enablepagemethods = " True " />
< Input type = " Button " Value = " Get current time " Onclick = " Getcurrenttime () " />
< Script Language = " Javascript " Type = " Text/JavaScript " >
function getcurrenttime ()
{< br> pagemethods. getcurrenttime (getcurrenttimesucceeded);
}< br>
function getcurrenttimesucceeded (result)
{< br> alert (result );
}< br> </ Script >
</ Form >
CSProtected VoidPage_load (ObjectSender, eventargs E)
{
}
[Webmethod]
Public StaticDatetime getcurrenttime ()
{
ReturnDatetime. utcnow;
}
If the error pagemethods is not defined, check the following:
1. Set the attribute enablepagemethods of scriptmanager to true.
2. Add [system. Web. Services. webmethod] To the called method.
3. Called FunctionsCodeThe master page cannot be loaded in CS. If the master page exists, add it to the CS page of the Child page.