Hi ,
How to not proceed the button click event on the regularvalidationexpression go on Invalid ,Can anyone suggest with example code .the validation working fine but its allow the click event on the codebehind .
source code :
Change Password
Thanks in advance
Karthik.K
4 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Jayraj ChhayaPosted Feb 1, 2024, 6:06 AM
To prevent the button click event from proceeding when the validation fails, you need to set the
CausesValidationproperty of thebtnSavebutton tofalse. This will bypass the validation controls and prevent the button click event from being triggered when the validation fails.Here's the updated code:
By setting
CausesValidationtofalse, the button click event will only be triggered if the validation is successful.Jignesh KumarPosted Feb 5, 2024, 4:01 AM
Hello Karthik,
You mean you want to do validation execution on client side and server side both, to make it work you need to set "EnableClientScript" to true.
Tuhin PaulPosted Feb 4, 2024, 6:02 PM
If you want to prevent the button click event from proceeding when the validation fails, you can use the Page_ClientValidate function in JavaScript. This function is automatically generated by ASP.NET when you use validation controls.
This JavaScript function (validate()) uses Page_ClientValidate('chkcharacters') to check whether all validation controls in the specified validation group (chkcharacters) have passed. If validation fails, it returns false, preventing the form submission. If validation passes, it returns true, allowing the form submission to proceed.
Note: The Page_ClientValidate function is automatically generated by ASP.NET when you use validation controls with ValidationGroup. Ensure that you have ClientIDMode set to AutoID or similar for your controls if you are using Master Pages or have other considerations for the client-side IDs.
Jithu ThomasPosted Jan 31, 2024, 11:48 AM
To prevent the button click event from proceeding when the regular expression validation fails, you can use the
Page_ClientValidatefunction in JavaScript to manually trigger client-side validation before allowing the form submission. Additionally, you can check thePage_IsValidproperty in your code-behind to ensure that server-side validation is also successful.Here's an example of how you can modify your code:
OnClientClickattribute to your button and call thevalidateFormJavaScript function:validateFormJavaScript function to your page:This JavaScript function performs the following:
Page.IsValidproperty to ensure server-side validation is successful.trueif both client-side and server-side validations pass, allowing the form submission.falseif either client-side or server-side validation fails, preventing the form submission.