Client Access pagemethod

Source: Internet
Author: User
• 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.