O'Reilly logo

ASP.NET jQuery Cookbook by Sonal Aneel Allana

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Consuming page methods with AJAX

There are two primary ways of using jQuery to communicate with ASP.NET code-behind based on events triggered on a web page:

  • using page methods
  • using web services

Page methods provide a handy way of invoking code-behind from client side script when simple server-side processing is required and when the application scope does not necessitate the calling of web services.

In this recipe, we will use AJAX to call a page method to check if the user name entered by the end user is valid.

Getting ready

  1. Add a new web form Recipe3.aspx to the current project.
  2. In the code-behind, add the following namespace to enable page methods:
    using System.Web.Services;
    
  3. Define an internal array object to store some UserNames in the system: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required