1

作为向导的第一步,我有许多文本框。

所有这些文本框都有一个 requiredfieldvalidator。

我需要找到一种方法来绕过这些验证或暂时忽略它们,因为我需要在向导结束时显示所有错误,作为单击完成之前的最后一步。

我遇到的问题是,在填写完所有文本框之前,向导不允许我导航到下一步。

有没有办法我可以忽略错误并在我的向导中导航并在我的向导结束时在验证摘要中使用它们?

这是我的 asp 代码:(我尝试将每个文本框的 CausesValidation 设置为 false,但这仍然不起作用)

            <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1 - Customer Information">

                <asp:Table runat="server" ID="UserInfoTable">

                    <asp:TableRow>
                        <asp:TableCell>
                            <asp:Label ID="Label2" runat="server" Text="Identification Number:"></asp:Label>&nbsp&nbsp
                        </asp:TableCell>

                        <asp:TableCell>
                            <asp:TextBox runat="server" ID="txtUserID" CausesValidation="false"></asp:TextBox>
                            <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator" ErrorMessage="*Required" ControlToValidate="txtUserID"></asp:RequiredFieldValidator><br />
                        </asp:TableCell>
                        </asp:TableRow>

                    <asp:TableRow>
                        <asp:TableCell>
                            <asp:Label ID="Label1" runat="server" Text="First Name:" CausesValidation="false"></asp:Label>&nbsp&nbsp
                        </asp:TableCell>

                        <asp:TableCell>
                            <asp:TextBox runat="server" ID="txtUserFName" CausesValidation="false"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*Required" ControlToValidate="txtUserFName"></asp:RequiredFieldValidator><br />
                        </asp:TableCell>                   
                    </asp:TableRow>

                    <asp:TableRow>
                        <asp:TableCell>
                            <asp:Label ID="Label3" runat="server" Text="Second Name:" CausesValidation="false"></asp:Label>&nbsp&nbsp
                        </asp:TableCell>
                        <asp:TableCell>
                            <asp:TextBox runat="server" ID="txtUserSurname"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*Required" ControlToValidate="txtUserSurname"></asp:RequiredFieldValidator><br />
                        </asp:TableCell>
                    </asp:TableRow>

                    <asp:TableRow>
                        <asp:TableCell>
                            <asp:Label ID="Label4" runat="server" Text="Street Addrress:" CausesValidation="false"></asp:Label>&nbsp&nbsp
                        </asp:TableCell>
                        <asp:TableCell>
                            <asp:TextBox runat="server" ID="txtUserAddress" CausesValidation="false"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*Required" ControlToValidate="txtUserAddress"></asp:RequiredFieldValidator><br />
                        </asp:TableCell>
                    </asp:TableRow>

                    <asp:TableRow>
                        <asp:TableCell>
                            <asp:Label ID="Label5" runat="server" Text="City:" CausesValidation="false"></asp:Label>&nbsp&nbsp
                        </asp:TableCell>
                        <asp:TableCell>
                            <asp:TextBox runat="server" ID="txtUserCity"></asp:TextBox>

                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="*Required" ControlToValidate="txtUserCity"></asp:RequiredFieldValidator><br />
                        </asp:TableCell>
                    </asp:TableRow>

                    <asp:TableRow>
                        <asp:TableCell>
                            <asp:Label ID="Label6" runat="server" Text="E-Mail:" CausesValidation="false"></asp:Label>&nbsp&nbsp
                        </asp:TableCell>
                        <asp:TableCell>
                            <asp:TextBox runat="server" ID="txtUserEmail"></asp:TextBox>

                            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="*Email address incorrect" ControlToValidate="txtUserEmail" ValidationExpression=".+@.+"></asp:RegularExpressionValidator><br />

                        </asp:TableCell>
                    </asp:TableRow>

                    <asp:TableRow>
                        <asp:TableCell>
                            <asp:Label ID="Label7" runat="server" Text="Contact Number:" CausesValidation="false"></asp:Label>&nbsp&nbsp
                        </asp:TableCell>
                        <asp:TableCell>
                            <asp:TextBox runat="server" ID="txtContactNo"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="*Required" ControlToValidate="txtContactNo"></asp:RequiredFieldValidator>


                            <br />
                        </asp:TableCell>
                    </asp:TableRow> 

                </asp:Table>
            </asp:WizardStep>

我知道如何使用验证摘要。所以我不需要帮助。我只需要知道如何禁用控件上的验证。

谢谢您的帮助。

4

1 回答 1

1

把问题解决了。。

解决方案是将所有验证器移至向导的最后一步。

这是我的代码作为示例:

        <asp:WizardStep ID="WizardStep4" runat="server" Title="Step 4 - Finalize booking">
            <h2>Finish</h2>
                <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Errors"/>


            <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator7" ErrorMessage="Customer ID required" ControlToValidate="txtUserID" Font-Bold="true" ForeColor="Red" Display="None"></asp:RequiredFieldValidator><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ErrorMessage="Customer first name required" ControlToValidate="txtUserFName" Font-Bold="true" ForeColor="Red" Display="None"></asp:RequiredFieldValidator><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" ErrorMessage="Customer last name required" ControlToValidate="txtUserSurname" Font-Bold="true" ForeColor="Red" Display="None"></asp:RequiredFieldValidator><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ErrorMessage="Customer address required" ControlToValidate="txtUserAddress" Font-Bold="true" ForeColor="Red" Display="None"></asp:RequiredFieldValidator><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator11" runat="server" ErrorMessage="Customer city required" ControlToValidate="txtUserCity" Font-Bold="true" ForeColor="Red" Display="None"></asp:RequiredFieldValidator><br />
            <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Email format is incorrect" ControlToValidate="txtUserEmail" ValidationExpression=".+@.+" Font-Bold="true" ForeColor="Red" Display="None"></asp:RegularExpressionValidator><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator12" runat="server" ErrorMessage="Contact number incorrect" ControlToValidate="txtContactNo" Font-Bold="true" ForeColor="Red" Display="None"></asp:RequiredFieldValidator>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator13" runat="server" ErrorMessage="Enter number of people for booking" Font-Bold="true" ForeColor="Red" ControlToValidate="txtNoOfPeople" Display="None"></asp:RequiredFieldValidator>

            </asp:WizardStep>
于 2013-09-04T17:32:36.760 回答