Validation control in detailsview

Last post 07-11-2009 12:04 PM by shtrudel. 4 replies.

Sort Posts:

  • Validation control in detailsview

    07-05-2009, 9:50 AM
    • Member
      148 point Member
    • shtrudel
    • Member since 03-09-2006, 10:55 AM
    • Posts 152

    Hello,


    I have a form with Gridview and detailsview controls that connected to the same objectdatasource.


    I use the gridview to list data from the datasource as well as let the user update data. I use the detailsview to let the user Insert new data.


    I converted the field of the detailsview into a template field and in the 'Insert template" I inserted a Required field validation control

    and set its properties to validate the right control.


    When trying to Insert  empty data into the detailsview control the validation control works fine, the problem starts when

    the user edit a row in the gridview control and than click the Update, in this situation the validation control of the detailsview

    doesn't let the update operation to take place in the gridview control.


    any ideas?



    The code is -


    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
                DataKeyNames="pk" DataSourceID="ObjectDataSource1" AllowPaging="True" PageSize="5">
                    <Columns>
                        <asp:CommandField ShowEditButton="True" />
                        <asp:BoundField DataField="teacher" HeaderText="teacher"
                        SortExpression="teacher" Visible="False" />
                        <asp:BoundField DataField="school" HeaderText="Class"
                        SortExpression="school" >
                            <ItemStyle Width="200px" />
                        </asp:BoundField>
                        <asp:BoundField DataField="pk" HeaderText="pk" InsertVisible="False"
                        ReadOnly="True" SortExpression="pk" Visible="False" />
                    </Columns>
     </asp:GridView>

    <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
                DataKeyNames="pk" DataSourceID="ObjectDataSource1" DefaultMode="Insert"
                Height="50px" Width="221px">
                    <Fields>
                        <asp:BoundField DataField="teacher" HeaderText="teacher"
                        SortExpression="teacher" Visible="False" />
                        <asp:TemplateField HeaderText="school" SortExpression="school">
                            
                            <InsertItemTemplate>
                                <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("school") %>'></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                                    ControlToValidate="TextBox2" ErrorMessage="*">*</asp:RequiredFieldValidator>
                            </InsertItemTemplate>
                            
                        </asp:TemplateField>
                        <asp:BoundField DataField="pk" HeaderText="pk" InsertVisible="False"
                        ReadOnly="True" SortExpression="pk" />
                        <asp:CommandField ShowInsertButton="True" />
                    </Fields>
    </asp:DetailsView>


    Cheers
  • Re: Validation control in detailsview

    07-05-2009, 11:23 AM
    • Contributor
      7,023 point Contributor
    • superguppie
    • Member since 05-19-2009, 11:42 AM
    • Posts 1,240
    The keyword for this is ValidationGroup. I don't know all the ins and outs of it, but the idea is you link validator and that which is validated by putting them in the same ValidationGroup. When something in a group is to be validated, only that group will be validated. Things without ValidationGroup will be validated on every PostBack.
    Superguppie.

    Please remember to click “Mark as Answer” on the post that helps you.
    This can be beneficial to other community members reading the thread.

    When all you've got is a Hammer,
    Every Problem looks like a Nail.
    Michael Swain.
  • Re: Validation control in detailsview

    07-06-2009, 1:01 AM
    • Member
      148 point Member
    • shtrudel
    • Member since 03-09-2006, 10:55 AM
    • Posts 152

    I tried adding validation control. Unfortunately the validation control of the detailesView still try to validate the

    Update event of the gridView control.


    Any other ideas

    Cheers
  • Re: Validation control in detailsview

    07-06-2009, 1:15 PM
    • Contributor
      7,023 point Contributor
    • superguppie
    • Member since 05-19-2009, 11:42 AM
    • Posts 1,240
    Did you give GridView and DetailsView different ValidationGroups? And did you apply that ValidationGroup to all buttons? You will have to put all Buttons in ButtonField and set ValidationGroup on that.
    If so, we'll have to hope for someone more knowledgable on validation to come by and answer.
    Superguppie.

    Please remember to click “Mark as Answer” on the post that helps you.
    This can be beneficial to other community members reading the thread.

    When all you've got is a Hammer,
    Every Problem looks like a Nail.
    Michael Swain.
  • Re: Validation control in detailsview

    07-11-2009, 12:04 PM
    • Member
      148 point Member
    • shtrudel
    • Member since 03-09-2006, 10:55 AM
    • Posts 152

    Hi again,


    YES it solve the problem. Using different validation groups did the work.


    Thanks

    Cheers
Page 1 of 1 (5 items)