Skip to content Skip to sidebar Skip to footer

Call A Javascript Method After The Requiredfieldvalidator Fires?

Is it possible to fire a JavaScript method after a form element is considered invalid? Here is my scenario: There are 2 tabs on the ASPX page. The user has to fill out info on both

Solution 1:

Unfortunately, the canned Field Validator controls in ASP.NET Webforms are not very extensible. I've had needs to change the CSS class of an input field to an invalid state upon client-side validation, and I never found a good way to handle this.

I think your best bet might be to do your own client-side validation. I've also looked into this third party product and it seemed to be pretty fully-functional, but I couldn't justify the cost in my case: http://www.peterblum.com/DES/Home.aspx

Solution 2:

You can call any js function from your server side code after the validation check on page object and inside the js function you can write the logic to highlight the field which has issue on validation:

if(!Page.IsValid)
    {

      Page.ClientScript.RegisterStartupScript(typeof(Page), "validate", "myjsfunction();", true);
    }
    else
    {
       // type code here
    }

Post a Comment for "Call A Javascript Method After The Requiredfieldvalidator Fires?"