ASP.NET – Multiple ValidationSummary

asp.netvalidation

Scenario: I am trying to insert a team (composed by multiple persons) on a single page. I have a web user control to insert each person, and when a team has multiple persons several Web User Controls are displayed at the same time.

Each user has a ValidationSummary and several validators (All grouped to the same validation group, example person1 web user control has the validation group on de Validation summary and on each validator set to "valGroup_Person1").

The problem is when validation occurs all errors are grouped and displayed in all web user controls making each web user control display a very long error list. The expected was individual error lists.

Is there a way to get ValidationSummary to perform this way?

Best Answer

If you are using asp.net 2.0 then you must use validation group this will work.

See the below example it will work

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" ErrorMessage="RequiredFieldValidator" ValidationGroup="1">1</asp:RequiredFieldValidator> <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBox2" ErrorMessage="RequiredFieldValidator2" ValidationGroup="2">2</asp:RequiredFieldValidator> <asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="1" /> <asp:ValidationSummary ID="ValidationSummary2" runat="server" ValidationGroup="2" /> <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="1" /> <asp:Button ID="Button2" runat="server" Text="Button" ValidationGroup="2" />

Related Topic