Wednesday, December 28, 2005

Validating in Groups

In ASP.NET 2.0 has a new feature called Validation Groups.

If supposing you have two different sections and each of the section needs to be validated separately then Validation Groups is an interesting concept.
Each control can be tied to a specific group by using the ValidationGroup property in the controls.

Here is a simple example in ASP.NET 2.0.
Copy it to an aspx page and run it.

<form id="form1" runat="server"><div><asp:Panel ID="Panel1" runat="server"><asp:TextBox ID="TextBox1" ValidationGroup="FirstGroup" runat="server" /><asp:RequiredFieldValidator ID="RequiredFieldValidator1"ErrorMessage="First Group Validated" ValidationGroup="FirstGroup"runat="server" ControlToValidate="TextBox1" /><asp:Button ID="Button1" Text="Validate Group1"ValidationGroup="FirstGroup" runat="server" /></asp:Panel><br /><asp:Panel Height="94px" ID="Panel2" runat="server" Width="125px"><asp:TextBox ID="TextBox2" ValidationGroup="SecondGroup"runat="server" /><asp:RequiredFieldValidator ID="RequiredFieldValidator2"ErrorMessage="Second Group Validated" ValidationGroup="SecondGroup"ControlToValidate="TextBox2" runat="server" /><asp:Button ID="Button2" Text="Validate Second Group"ValidationGroup="SecondGroup" runat="server" /></asp:Panel></div></form>


0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home