开发者

ASP.NET Form validation - success event in JavaScript?

开发者 https://www.devze.com 2023-03-02 03:09 出处:网络
I would like to subscribe to whatever event is fired when my ASP.NET form is validated successfully. Here is the scenario: On the click of a button on a payment form, 开发者_运维技巧I want to show a

I would like to subscribe to whatever event is fired when my ASP.NET form is validated successfully.

Here is the scenario: On the click of a button on a payment form, 开发者_运维技巧I want to show a message 'processing,' however I only want to show this button when the for is validated succesfully.

I am using native ASP.NET form validation.


In a round-about way, you can if you override the Page_ClientValidate method as in:

var fn = Page_ClientValidate;
Page_ClientValidate = function(..) {
    var result = fn(..);

    if (result == true) {
        //run code for success
    }
}

I don't know why this was demoted but this approach is great because it works from all validation scenarios for customization (from buttons, WebForms_DoPostBackWithOptions client method, etc.).

HTH.


I don't think that the built in validators expose any such events. You could always use the CustomValidator and provide a OnClientValidate method that will combine the validation you're looking for as well as the UI changes you desire.


Call the following Javascript function whenever you want and pass the validation group name of your form to it..

function ValidateForm(ValidationGroupName)
{
    var validated=Page_ClientValidate(ValidationGroupName); 
    if(validated)
     {
        //do the logic here
        return true;
      }
      else
      {
        return false;
       }
  }

Hope this will help you....


I don't think it's going to be easy to do it your way but what you can do is the following:

<asp:Button onclientclick="if (Page_IsValid) return true; else {alert('Not Valid'); return false;}"/>

This will basically throw an error is validation is incorrect, otherwise it will continue.

0

精彩评论

暂无评论...
验证码 换一张
取 消