Thursday, January 27, 2011

Using ASP.NET AJAX PageMethods and Validators

I have a basic CRUD form that uses PageMethods to update the user details, however the Validators don't fire off, I think I need to manually initialize the validators and check whether the validation has passed in my javascript save method. Any ideas on how to do this?

  • what are you using for development? VS 2008 supposedly has better JS debugging, haven't tried it yet.

    For Ajax you can use the Sys.Debug obj

  • If you use Firefox, you can use the FireBug plugin. It has great javascript debugging support.

    From Dale Ragan
  • Ok so I finally solved this: You need to call Page_ClientValidate() in your Save javascript method and If it returns true continue with the save, the Page_ClientValidate() initiates the client side validators, See code below:

     function Save()
     {
      var clientValidationPassed =Page_ClientValidate();
      if(clientValidationPassed)
      {
       //Save Data
       PageMethods.SaveUser(UserName,Role,SaveCustomerRequestComplete, RequestError);
       $find('editPopupExtender').hide();
      }
      else
      {
       //Do Nothing as CLient Validation messages are now displayed
      }
      return false;
     }
    
    From Nicholas

0 comments:

Post a Comment