Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Monday, September 15, 2008

OnClientClick and Form Validation in


When we use OnClienClick script for a button in, you can notice that all the associated validation controls (validation group) will fail to validate. This happens because the OnClientClick script overrides form validation script.

To fix this, here is the work around.Add the below code in Page Load event

Button1.Attributes.Add("onclick", "if(confirm('do this ?') == false) return false;");

This will execute the client script and then executes the form validations scripts before post back.

Post a Comment

Anonymous said...

Found a better solution at

This does validation before prompting user 'Are you sure?'.

if (Page_ClientValidate()){return confirm('Are you sure you want to perform this action?')}