ASP.NET - Multiple Validation
Script . I am trying to embed a team (consisting of several people) in one page. I have a web user control to insert each person and when a team has multiple people, multiple web user controls are displayed at the same time.
Each user has a ValidationSummary and multiple validators (all grouped into the same validation group, for example the user control person1 example1 has a validation group in the validation summary and on each validator set to "valGroup_Person1").
The problem is that when checked, all errors are grouped and displayed in all web user controls, and each custom control displays a very long list of errors. Separate error lists were expected.
Is there a way to force ValidationSummary to execute this path?
a source to share
If you are using asp.net 2.0 you must use a review group, this will work.
See example below, 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" />
a source to share
You must disambiguate the validation groups from each other by giving them separate names on each of the controls. For example, on the user management page:
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim uniqueGroupName = Guid.NewGuid.ToString
valSummary.ValidationGroup = uniqueGroupName
txtFirstName.ValidationGroup = uniqueGroupName
txtLastName.ValidationGroup = uniqueGroupName
btnFind.ValidationGroup = uniqueGroupName
End Sub
(for each control in the group, programmatically give it a check group)
If you are doing server side validation, you should invoke group only validation, eg.
Page.Validate(valSummary.ValidationGroup)
If Not Page.IsValid then Exit Sub
...