0

任何人都可以帮助我吗?当我将 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"/>`

这是编辑事件选项卡的代码>>>

        <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 后,它不会将我的表单视图更新到数据库

4

1 回答 1

0

尝试向ValidationGroupFormView 中的按钮添加一个。与导致 formview 更新失败的必填字段验证器相比,请确保使用不同的组名。

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

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

编辑:只是为了检查。如果添加CausesValidation="False"更新按钮会发生什么?

于 2012-07-07T05:55:24.100 回答