locked
Issue with FormView Validation using Dynamic Data RRS feed

  • Question

  • User-10017267 posted

    I'm having some issues with the validation on my FormView using Dynamic data.

    I have a DetailsView where the validation works, but I can't seem to see why it does not work in my FormView.

    I have attached some code for review: My FormView "CommentsFormView" does not trigger the validation for some reason.

    See below:

    <%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.master" CodeFile="ActivityDetails.aspx.cs"
        Inherits="Secure_TrafficLight_TLRTasks" MaintainScrollPositionOnPostback="true"
        Theme="Theme1" %>
    
    <%@ MasterType VirtualPath="~/Site.master" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
        <style type="text/css">
            
        </style>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
     <asp:Panel ID="CommentsPanel" runat="server" Visible="false" Style="display: none;"
                    CssClass="modalPopup">
                    <asp:Label ID="ErrorMessageLabel" runat="server" CssClass="forecolorRed" Text=""></asp:Label>
                    <br />
                    <br />
                    <asp:ValidationSummary ID="CommentsFormViewValidationSummary" runat="server" EnableClientScript="true"
                        HeaderText="Validation errors" CssClass="DDValidator" ValidationGroup="CommentsFormViewValidationGroup" />
                    <asp:DynamicValidator ID="DynamicValidator1" runat="server" ControlToValidate="CommentsFormView"
                        ValidationGroup="CommentsFormViewValidationGroup" />
                    <asp:FormView ID="CommentsFormView" runat="server" AllowPaging="True" BackColor="White"
                        DataKeyNames="CommentsID" DataSourceID="CommentsLinqDataSource" GridLines="None"
                        DefaultMode="ReadOnly" CssClass="" SkinID="SampleFormView" EnableModelValidation="true"
                        OnItemInserted="CommentsFormView_ItemInserted" OnItemInserting="CommentsFormView_ItemInserting">
                        <%--OnItemInserting="CommentsFormView_ItemInserting"--%>
                        <EditItemTemplate>
                            <asp:Label ID="EditCommentHeadingLabel" runat="server" Text="Edit mode"></asp:Label>
                            <tr>
                                <td>
                                    Comment type:
                                </td>
                                <td>
                                    <asp:DynamicControl ID="CommentTypeDynamicControl" runat="server" DataField="CommentType"
                                        Mode="Edit" ValidationGroup="CommentsFormViewValidationGroup" />
                                    <tr>
                                        <td>
                                            Title:
                                        </td>
                                        <td>
                                            <asp:DynamicControl ID="TitleDynamicControl" runat="server" DataField="Title" Mode="Edit"
                                                ValidationGroup="CommentsFormViewValidationGroup" />
                                        </td>
                                    </tr>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Comment:
                                </td>
                                <td>
                                    <asp:DynamicControl ID="CommentsDynamicControl" runat="server" DataField="Comments"
                                        Mode="Edit" ValidationGroup="CommentsFormViewValidationGroup" UIHint="MultilineText" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                                        Text="Update" ValidationGroup="Insert" />
                                    &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False"
                                        CommandName="Cancel" Text="Cancel" />
                                </td>
                            </tr>
                        </EditItemTemplate>
                        <InsertItemTemplate>
                            <asp:Label ID="EditCommentHeadingLabel" runat="server" Text="Activity comment" CssClass="sectionLabelBlue"></asp:Label>
                            <br />
                            <br />
                            <tr>
                                <td>
                                    Title:
                                </td>
                                <td>
                                    <asp:DynamicControl ID="TitleDynamicControl" runat="server" DataField="Title" Mode="Insert"
                                        ValidationGroup="CommentsFormViewValidationGroup" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Comment type:
                                </td>
                                <td>
                                    <asp:DynamicControl ID="CommentTypeDynamicControl" runat="server" DataField="CommentType"
                                        Mode="Insert" ValidationGroup="CommentsFormViewValidationGroup" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Name:
                                </td>
                                <td>
                                    <asp:DynamicControl ID="NameDynamicControl" runat="server" DataField="Name" Mode="Insert"
                                        ValidationGroup="CommentsFormViewValidationGroup" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Comments:
                                </td>
                                <td>
                                    <asp:DynamicControl ID="CommentsDynamicControl" runat="server" DataField="Comments"
                                        Mode="Insert" ValidationGroup="CommentsFormViewValidationGroup" UIHint="MultilineText" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                </td>
                                <td>
                                    <asp:DropDownList ID="ActivityIDDropDownList" runat="server" DataSourceID="ActivityForDropDownLinqDataSource"
                                        DataTextField="ActivityName" DataValueField="ActivityID" Visible="false" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <br />
                                    <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                                        Text="Insert" ValidationGroup="Insert" />
                                    &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
                                        CommandName="Cancel" Text="Cancel" />
                                </td>
                            </tr>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <tr>
                                <td>
                                    Comment type:
                                </td>
                                <td>
                                    <asp:DynamicControl ID="CommentTypeDynamicControl" runat="server" DataField="CommentType"
                                        Mode="ReadOnly" ValidationGroup="CommentsFormViewValidationGroup" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Title:
                                </td>
                                <td>
                                    <asp:DynamicControl ID="TitleDynamicControl" runat="server" DataField="Title" Mode="ReadOnly"
                                        ValidationGroup="CommentsFormViewValidationGroup" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Comments ID:
                                </td>
                                <td>
                                    <asp:DynamicControl ID="CommentsIDDynamicControl" runat="server" DataField="CommentsID"
                                        Mode="ReadOnly" ValidationGroup="CommentsFormViewValidationGroup" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Comments:
                                </td>
                                <td>
                                    <asp:DynamicControl ID="CommentsDynamicControl" runat="server" DataField="Comments"
                                        Mode="ReadOnly" ValidationGroup="CommentsFormViewValidationGroup" UIHint="MultilineText" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Date:
                                </td>
                                <td>
                                    <asp:DynamicControl ID="DateDynamicControl" runat="server" DataField="Date" Mode="ReadOnly"
                                        ValidationGroup="CommentsFormViewValidationGroup" />
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    Name:
                                </td>
                                <td>
                                    <asp:DynamicControl ID="NameDynamicControl" runat="server" DataField="Name" Mode="ReadOnly"
                                        ValidationGroup="CommentsFormViewValidationGroup" />
                                </td>
                            </tr>
                            <asp:LinkButton ID="EditButton" runat="server" CausesValidation="True" CommandName="Edit"
                                Text="Edit" ValidationGroup="Edit" />
                            <asp:LinkButton ID="NewButton" Text="New" CommandName="New" runat="server" />
                        </ItemTemplate>
                    </asp:FormView>
                </asp:Panel>
                <br />
                <asp:LinqDataSource ID="ActivityForDropDownLinqDataSource" runat="server" ContextTypeName="TPS_MainDataContext"
                    EntityTypeName="" Select="new (ActivityID, ActivityName)" TableName="Activities"
                    Where="ActivityID == @ActivityID">
                    <WhereParameters>
                        <asp:QueryStringParameter Name="ActivityID" QueryStringField="acid" Type="Int32" />
                    </WhereParameters>
                </asp:LinqDataSource>
                <asp:LinqDataSource ID="CommentsLinqDataSource" runat="server" ContextTypeName="TPS_MainDataContext"
                    EntityTypeName="" TableName="Comments" Where="ActivityID == @ActivityID" EnableInsert="true"
                    EnableUpdate="true" OnInserting="CommentsLinqDataSource_ItemInserting">
                    <%----%>
                    <WhereParameters>
                        <asp:QueryStringParameter DefaultValue="-1" Name="ActivityID" QueryStringField="acid"
                            Type="Int32" />
                    </WhereParameters>
                </asp:LinqDataSource>
                <asp:DynamicDataManager ID="ActivityDetailsDynamicDataManager" runat="server" AutoLoadForeignKeys="true">
                    <%--        <DataControls>
                <asp:DataControlReference ControlID="CommentsFormView"  />
            </DataControls>--%>
                </asp:DynamicDataManager>
    
    </asp:Content>
    
    
    Wednesday, September 28, 2011 2:00 AM

Answers

  • User617492218 posted

    i'm thinking b/c your LinkButtons have their ValidationGroup="Insert" instead of 

    CommentsFormViewValidationGroup

       <td>
              <asp:DynamicControl ID="TitleDynamicControl" runat="server" DataField="Title" Mode="Edit"
               ValidationGroup="CommentsFormViewValidationGroup" />
       </td>
        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
            Text="Update" ValidationGroup="Insert" />

    the same goes w/ your EditTemplate and InsertTemplate

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 28, 2011 9:18 AM

All replies

  • User617492218 posted

    i'm thinking b/c your LinkButtons have their ValidationGroup="Insert" instead of 

    CommentsFormViewValidationGroup

       <td>
              <asp:DynamicControl ID="TitleDynamicControl" runat="server" DataField="Title" Mode="Edit"
               ValidationGroup="CommentsFormViewValidationGroup" />
       </td>
        <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
            Text="Update" ValidationGroup="Insert" />

    the same goes w/ your EditTemplate and InsertTemplate

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, September 28, 2011 9:18 AM
  • User-10017267 posted

    It works!  Thankyou so much for that.

    Wednesday, September 28, 2011 8:18 PM