ValidationGroup example in Asp.Net

In this post, we will discuss how to use ValidationGroup in Asp.Net.

New to Office 365 SharePoint Online? Get Office 365 Enterprise E3 Subscription & Try out all the features

You can also check my previous posts on ValidationSummaryRequiredFieldValidator, RangeValidator, RegularExpressionValidator examples in Asp.Net.

If your page has several groups of controls and you want to perform validation separately then ValidationGroup will be very much helpful.

You have to assign ValidationGroup to controls, validators, and buttons. Here in this example, we have two panels.

Below is the .aspx code:

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”ValidatorExamples.aspx.cs”
Inherits=”ValidatorExamples” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “”>
<html xmlns=””>
<head runat=”server”>
<title>ValidationGroup example in Asp.Net</title>
<form id=”form1″ runat=”server”>
<asp:Panel ID=”pnlLogin” runat=”server”>
Enter EmailID:<asp:TextBox ID=”txtEmailIDLogin” runat=”server” ValidationGroup=”Group1″></asp:TextBox><br />
<asp:RequiredFieldValidator ID=”RequiredFieldValidator1″ runat=”server” ForeColor=”Red”
ValidationGroup=”Group1″ ErrorMessage=”Enter Email ID!” ControlToValidate=”txtEmailIDLogin”></asp:RequiredFieldValidator><br />
<asp:Button ID=”btnLogin” runat=”server” Text=”Submit” ValidationGroup=”Group1″ />
<asp:Panel ID=”pnlSignup” runat=”server”>
Enter EmailID: <asp:TextBox ID=”txtEmailIDSignUp” runat=”server” ValidationGroup=”Group2″> </asp:TextBox>
<br />
<asp:RequiredFieldValidator ID=”RequiredFieldValidator2″ runat=”server” ForeColor=”Red” ErrorMessage=”Enter Email ID!” ControlToValidate=”txtEmailIDSignUp” ValidationGroup=”Group2″></asp:RequiredFieldValidator>
<br />
<asp:Button ID=”btnSignup” runat=”server” Text=”Submit” ValidationGroup=”Group2″/>

Here if you click on first button then only 1st textbox will get validated. And also if you click on second button then 2nd textbox will get validated like below figure.

Check out Best Alternative to InfoPath -> Try Now


(Installation & Features)

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site

View all posts by Bijay Kumar →