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 :
Code
Change Password
Old Password
Password
Repeat Password
** You should change the Default Password with Strong Password **
** Your Password should contains 1 Uppercase,1 Alphabet
1 Lowercase,1 Number,1 Special Character **Thanks in advance
Karthik.K


Jayraj ChhayaRank #304 · 8.2K reputationPosted Feb 1, 2024, 1:06 AM EST
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.Jithu ThomasRank #437 · 5.7K reputationPosted Jan 31, 2024, 6:48 AM EST
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:function validateForm() { // Trigger client-side validation var isValid = Page_ClientValidate('chkcharacters'); // Check if client-side validation passed if (isValid) { // Check if server-side validation passed if () { return true; // Allow form submission } else { return false; // Server-side validation failed } } else { return false; // Client-side validation failed } }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.Tuhin PaulRank #7 · 71.9K reputationPosted Feb 4, 2024, 1:02 PM EST
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.
Jignesh KumarRank #91 · 22.9K reputationPosted Feb 4, 2024, 11:01 PM EST
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.