How to call a C# Web(Page) Method from Javascript using ScriptManager

Atlas (Javascript Library) gave us the ability to easily call Web method from JavaScript. Microsoft AJAX has gone one step further! We can now call web methods in the code behind of the current page from Javascript. Here’s how:
For Enable Page Methods on your ScriptManager set the EnablePageMethods=”true” attribute

For this you must mark your method as static and give it the Web-method attribute. The method has to be declared static. It must also be marked with the WebMethod attribute. You’ll probably find that you need to include System.Web.Services

For Call it from Javascript you need to call the method from javascript you need to append PageMethods. to the front of the method name.

Tagged , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.