views:

1282

answers:

2

Hello,

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?

Thanks

A: 

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

See the below example it will work

79db078f45a7f300ca8be180b7ababc4
<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" />

jalpesh
I only have one button to submit everything...
Sergio
then you have to check it from the server side or you need to move to the another validation farmework.Built in validation does not support this. See the below linkhttp://dotnetslackers.com/Community/blogs/bmains/archive/2007/10/10/validation-summary-and-multiple-validation-groups.aspx
jalpesh
You need to some thing like following in your buttons click eventPage.Validate("validationGroup")
jalpesh
A: 

You have to disambiguate the validation groups from each other by giving them separate names on each of the controls. For example, in the user control's page-init:

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 validation group)

If you are doing server-side validation, you should call validation for just the group, e.g.

Page.Validate(valSummary.ValidationGroup)
If Not Page.IsValid then Exit Sub
...
Steve Campbell