Imagine a page with a group of fields for collecting data and separate group of fields for searching your site. Each group of fields has its own Submit button. When the user clicks one button, the validators of the other group should not be validated and block submitting the page. With the Validation Groups feature, you can assign a group name to the Group property of each validator, the ValidationSummary and the submit buttons.
Microsoft's validators implement a very similar system. However, Peter's Professional Validators has several improvements over the native validators:
This demo page has two groups of fields. Each has its own Submit button that will only validate its own field. Click each Submit button to see its own validation error appear. (Leave the textboxes blank as its validating the textbox has text.) Use the Reset button to start over.
<div width="100%" runat="server" id="Group1" style="BORDER-RIGHT: coral thin solid; BORDER-TOP: coral thin solid; BORDER-LEFT: coral thin solid; BORDER-BOTTOM: coral thin solid; BACKGROUND-COLOR: antiquewhite"> <b>Group 1</b><br> <asp:TextBox id="TextBox1" runat="server"></asp:TextBox> <des:RequiredTextValidator id="RequiredTextValidator1" runat="server" ControlIDToEvaluate="TextBox1" ErrorMessage="This field is required" Group="Group1"> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic"></des:TextErrorFormatter> </ErrorFormatterContainer> </des:RequiredTextValidator> <des:DataTypeCheckValidator id="DataTypeCheckValidator1" runat="server" ControlIDToEvaluate="TextBox1" ErrorMessage="Enter a number" DataType="Integer" Group="Group1"> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic"></des:TextErrorFormatter> </ErrorFormatterContainer> </des:DataTypeCheckValidator> <br> <des:Button id="Button1" runat="server" Group="Group1" Text="Submit"></des:Button><br> </div> <br><br> <div width="100%" runat="server" id="Div1" style="BORDER-RIGHT: royalblue thin solid; BORDER-TOP: royalblue thin solid; BORDER-LEFT: royalblue thin solid; BORDER-BOTTOM: royalblue thin solid; BACKGROUND-COLOR: lightblue"> <b>Group 2</b><br> <asp:TextBox id="Textbox2" runat="server"></asp:TextBox> <des:RequiredTextValidator id="Requiredtextvalidator2" runat="server" ControlIDToEvaluate="TextBox2" ErrorMessage="This field is required" Group="Group2"> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic"></des:TextErrorFormatter> </ErrorFormatterContainer> </des:RequiredTextValidator> <des:DataTypeCheckValidator id="DataTypeCheckValidator2" runat="server" ControlIDToEvaluate="TextBox2" ErrorMessage="Enter a number" DataType="Integer" Group="Group2"> <ErrorFormatterContainer> <des:TextErrorFormatter Display="Dynamic"></des:TextErrorFormatter> </ErrorFormatterContainer> </des:DataTypeCheckValidator> <br> <des:Button id="Button2" runat="server" Group="Group2" Text="Submit"></des:Button><br> </div> <des:Button id="Button3" runat="server" Group="*" Text="Validation Both Groups"></des:Button> <input type="reset" value="Reset" />