Ad

Using ASP.NET AJAX PageMethods And Validators

- 1 answer

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?

Ad

Answer

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;
    }
Ad
source: stackoverflow.com
Ad