requiredfieldvalidator与formview冲突

时间:2012-07-07 03:57:16

标签: c# asp.net

任何人都可以帮我吗?当我在我的创建事件的tabcontainer上放置requiredfieldvalidator时,我无法更新我在另一个标签上的表单视图>>>编辑活动的标签。 我完全不知道发生了什么,并且当我试错时,我发现requiredfieldvalidator是导致我的formview停止更新到我的数据库的那个。我和这个requiredfieldvalidator在另一个标签上,所以它是如何影响的?!?!? 请指明或显示,因为我真的真的很新又坏!

以下是创建标签>>>

的代码
    <asp:TextBox ID="tb_eventName" runat="server" ValidationGroup="vg"></asp:TextBox>

    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                    ControlToValidate="tb_eventName" ErrorMessage="Enter event" 
                    ForeColor="Red" ValidationGroup="vg" SetFocusOnError="True" >*        </asp:RequiredFieldValidator>

        <asp:Button ID="bn_createEvent" runat="server"  
                    Text="Create Event" onclick="bn_createEvent_Click"    ValidationGroup="vg"/>`

以下是编辑活动标签的代码&gt;&gt;&gt;

        <asp:FormView ID="FormView1" runat="server" CellPadding="4" DataKeyNames="eventID" 
                    DataSourceID="SqlDataSource2" 
                    OnItemDeleted="FormView1_ItemDeleted"   OnItemInserted="FormView1_ItemInserted" 
                    OnItemUpdated="FormView1_ItemUpdated" ForeColor="Black"   BackColor="White" 
                    BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" 
                    GridLines="Vertical" >
                    <EditItemTemplate>
                        ID:
                        <asp:Label ID="eventIDLabel1" runat="server" Text='<%#   Eval("eventID") %>' />
                        <br />
                        <br />
                        Name:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                        <asp:TextBox ID="eventNameTextBox" runat="server" 
                            Text='<%# Bind("eventName") %>' />
                        &nbsp&nbsp
                        <br />
                        <br />


                        Date:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                        <asp:TextBox ID="eventDateTextBox" runat="server" 
                            Text='<%# Bind("eventDate") %>' />
                        <br />
                        <br />

                        Start-Time:&nbsp
                        <asp:TextBox ID="eventStartTimeTextBox" runat="server" 
                            Text='<%# Bind("eventStartTime") %>' />
                        <br />
                        <br />

                        End-Time:&nbsp&nbsp&nbsp
                        <asp:TextBox ID="eventEndTimeTextBox" runat="server" 
                            Text='<%# Bind("eventEndTime") %>' />
                        <br />
                        <br />

                        Location:&nbsp&nbsp&nbsp&nbsp&nbsp
                        <asp:TextBox ID="eventLocationTextBox" runat="server" 
                            Text='<%# Bind("eventLocation") %>' />
                        <br />
                        <br />

                        Email:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                        <asp:TextBox ID="eventEmailTextBox" runat="server" 
                            Text='<%# Bind("eventEmail") %>' />
                        <br />
                        <br />

                        Contact No:&nbsp
                        <asp:TextBox ID="eventContactNoTextBox" runat="server" 
                            Text='<%# Bind("eventContactNo") %>' />
                        <br />
                        <br />

                        Description:
                        <asp:TextBox ID="eventDescriptionTextBox" runat="server" 
                            Text='<%# Bind("eventDescription") %>' />
                        <br />
                        <br />

                        Image:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp
                        <asp:TextBox ID="eventImageTextBox" runat="server" 
                            Text='<%# Bind("eventImage") %>' />
                        <br />
                        <br />

                        <asp:LinkButton ID="UpdateButton" runat="server" 
                            CommandName="Update" Text="Update" />

`

添加requiredfieldvalidator后,它不会将我的formview更新到数据库

1 个答案:

答案 0 :(得分:0)

尝试将ValidationGroup添加到FormView中的按钮。与导致formview更新失败的必需字段验证程序相比,请确保使用不同的组名。

<asp:LinkButton ID="UpdateButton" runat="server"
    CommandName="Update" Text="Update"
    ValidationGroup="formViewValidation" />

这应该使它成为req。单击“更新”按钮时,不会触发vg的字段验证器。

修改:只是为了检查。如果在“更新”按钮上添加CausesValidation="False"会发生什么?