Page Methods is a new mechanism in ASP.Net application where the server code cab be bound to Asp.Net pages. It is an easy way to communicate asynchronously with the server using Asp.Net Ajax technologies. It’s an alternate way to call the page which is reliable and low risk. In a nutshell, it is used to expose the web methods to the client script.
To enable Page methods we need to drag a ScriptManager control to the page and mark the EnablePageMethods to True.
- Go the Code behind file of the page and add a static method and mark them as WebMethod. Lets Say the method name is GetPageMethod which returns a status value.
- Now that the method is exposed add a button control and call a client script which accesses the Webmethods of the page.
- Now run the application and check the result which shows the alert box with value “Welcome PageMethods”. The sample application calls the webmethods of the page using client script without full page cycle.