Validation Server Control
 
Dealing with Validation Groups
 
In earlier versions of ASP.NET (ASP.Net 1.0/1.1), on submitting a form, all the existed controls on the page were being validated. So on pressing the Submit button, each and every TextBox or other control that has a validator, was checked. This caused a problem when you had multiple forms on a page, with two or more submit buttons. Pressing one of the buttons would start to validate all the controls on a page, and which is not required.
 
This prevented developers to use multiple form submission from a single page.
 
This drawback is overcome in ASP.Net 2.0 using Validation groups. Grouping of controls is achieved in ASP.Net 2.0 by modifying the properties of the form controls, button controls and validation controls to have an additional property called the ValidationGroup. We need to set the same validation group name for all the controls that needs to be grouped under a same group with the validation controls.
 
Controls in different validation groups are validated separately.
 
Another new property called SetFocusOnError has been added to validation controls. It helps the page to focus on control that creates the error after form submission.
 
 
 
<form id="form1" runat="server">
<div>
<asp:TextBox ID="textbox_1" Runat="server" ValidationGroup="First"></asp:TextBox>
<asp:TextBox ID="textbox_2" Runat="server" ValidationGroup="First"></asp:TextBox><br />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" Runat="server" ValidationGroup="First"
ErrorMessage="textbox_1 should not be blank" ControlToValidate="textbox_1">
</asp:RequiredFieldValidator>
<asp:Button ID="Submit_1" Runat="server" ValidationGroup="First" Text="Submit 1" />
<br />
<asp:TextBox ID="textbox_3" Runat="server" ValidationGroup="Second"></asp:TextBox>
<asp:TextBox ID="textbox_4" Runat="server" ValidationGroup="Second"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" Runat="server" ErrorMessage=" textbox_3 should not be blank"
ControlToValidate="textbox_3" ValidationGroup="Second">
</asp:RequiredFieldValidator>
<asp:Button ID="Submit_2" Runat="server" ValidationGroup="Second"
Text="Submit 2" />\
</div></form>