ASP.Net How to show multiple validation group on Submit Button (Single Button)

Its little bit complex to show different validation group on signle Submit button click validation

To achieve this or show all validation (which has different validation group ) check below code

Page contains 3 validation groups

1. mailvalidation — Validation for Email Address
2. Uasenamevalidation — Check Username and validation
3. Page — All other Control Validation Group

ASP.Net Button Syntax:

<asp:Button ID="btnSave" runat="server" Text="Submit" OnClientClick="return Validate()" /></pre>

JavaScript Code :


<script type="text/javascript">
function Validate() {
var isEmailValidation = Page_ClientValidate("mailvalidation");
var isUserNameValidation = Page_ClientValidate('Uasenamevalidation');
var isControls = Page_ClientValidate("Page");

if (isEmailValidation && isUserNameValidation && isControls)
return true;
else
var i;
for (i = 0; i < Page_Validators.length; i++) {
ValidatorValidate(Page_Validators[i]); //this forces validation in all groups
}
return false;
}
</script>

In above script Else part forces validation of all groups which are remaining and will show message.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s