Erwin
Erwin

Reputation: 1502

ASP.NET validation summary inside formview doesn't work

I have a validation summary inside a asp.net formview and the validators just don't seem to trigger the validation summary.

Things I already tried:

Anyone has any ideas on how to handle this?

Code. Formview declaration:

<asp:FormView ID="FormViewPerson" runat="server" DataSourceID="ObjectDataSourcePerson"
    DefaultMode="Edit" OnItemUpdating="FormViewPerson_ItemUpdating" OnItemCommand="FormViewPerson_ItemCommand"
    OnItemUpdated="FormViewPerson_ItemUpdated" Width="100%">

Any of the textboxes with the validator:

<td>  <asp:TextBox ID="NumberTextBox" runat="server" Text='<%# Bind("Number") %>' 
                        TabIndex="10" CausesValidation="True" ClientIDMode="Static" />
                    <asp:RequiredFieldValidator ID="RequiredFieldValidatorNumber" runat="server" ControlToValidate="NumberTextBox"
                        ErrorMessage="Number is Required" ForeColor="Red" 
                        ValidationGroup="EditPerson">*</asp:RequiredFieldValidator>
                </td>

And the submitbutton:

<asp:ValidationSummary ID="ValidationSummaryPerson" runat="server" 
            ForeColor="Red" ClientIDMode="Static" CssClass="validation" 
            ShowMessageBox="True" ValidationGroup="EditPerson" ViewStateMode="Enabled"
            />
        <asp:Button ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
            Text="Save" ValidationGroup="EditPerson" CssClass="ButtonStyle" TabIndex="90" />
        &nbsp;<asp:Button ID="EditCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
            Text="Cancel" CssClass="ButtonStyle" TabIndex="100" 
            ValidationGroup="EditPerson" />

Upvotes: 1

Views: 4968

Answers (2)

Erwin
Erwin

Reputation: 1502

Well, I fixed the issue. If anyone else encounters this problem try the following:

  • Ensure there is only one (1) validation group on the entire form.
  • Set "causesvalidation" to "true" on the submitbutton.
  • Check, double check and triple check the spelling of your validationgroup property on all relevant controls.
  • Be on the lookout for javascript errors in your client-side scripts. They can cause havoc.

Upvotes: 1

V4Vendetta
V4Vendetta

Reputation: 38200

Hope the CausesValidation for the button is set to true.

Upvotes: 1

Related Questions