Validation Groups:

Posted on

Validation Groups:

Complex pages have different groups of information provided in different panels. In such a situation a need for performing validation separately for separate group, might arise. This kind of situation is handled using validation groups. To create a validation group, you should put the input controls and the validation controls into the same logical group by setting their ValidationGroup property.

Example:
The following example describes a form to be filled up by all the students of a school, divided into four houses, for electing the school president. We will be using the validation controls to validate the user input.

The content file code:

Candidate:

Please Choose a Candidate
M H Kabir
Steve Taylor
John Abraham
Venus Williams

House:

Red
Blue
Yellow
Green

Class:
Email:

The code behind the submit button:
protected void btnsubmit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{ lblmsg.Text = “Thank You”; }
else
{ lblmsg.Text = “Fill up all the fields”; }}