0

好的,两天后这仍然会导致问题.. 我有一个由几个文本字段和一个下拉列表和一个注册按钮组成的 asp.net 表单。

问题:当我将客户端验证器应用于文本字段并下拉时,按钮单击事件被禁止(对于页面上的所有按钮;不仅对于提交按钮,而且对于从 MasterPage 继承的全局导航按钮)。某些字段有多个验证器(例如,必填字段和 reg ex)。

当我注释掉任何验证器时,所有按钮的点击事件都会按预期运行。

我似乎很疯狂地插入一个额外的不需要的“虚拟”验证器只是为了注释掉,但它似乎只适用于 n-1 个验证器(即无论我在页面上有多少验证器,它只会适用于任何其中一个注释掉了)。

网络上到处都有指向 aspalliance.com 上有关此确切主题的文章的链接,但遗憾的是,该链接已损坏。有人可以提出解决方案吗?

谢谢,达夫。

更新...标记代码如下:

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Admin.Master" AutoEventWireup="true" CodeBehind="RegisterUser.aspx.cs" Inherits="LectureQuestions.Interface.Admin.RegisterUser" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PageTitle" runat="server">Register New User
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="TitleTxt" runat="server">Register New User
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <table ID="tblInputField" runat="server" width="100%" cellspacing="15">
            <tr>
                <td width="10%"></td>
                <td width="20%">First Name</td>
                <td width="60%">
                    <asp:TextBox ID="txtFirstName" runat="server" Width="98%"></asp:TextBox>
                </td>
                <td width="10%">
                    <asp:RequiredFieldValidator ID="txtFirstNameRequired" runat="server" Display="Dynamic"
                        ValidationGroup="InputValidate" ControlToValidate="txtFirstName" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td width="10%"></td>
                <td width="20%">Last Name</td>
                <td width="60%">
                    <asp:TextBox ID="txtLastName" runat="server" Width="98%"></asp:TextBox>
                </td>
                <td width="10%">
                    <asp:RequiredFieldValidator ID="txtLastNameRequired" runat="server" Display="Dynamic"
                        ValidationGroup="InputValidate" ControlToValidate="txtLastName" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td width="10%"></td>
                <td width="20%">E-mail</td>
                <td width="60%">
                    <asp:TextBox ID="txtEmail" runat="server" Width="98%"></asp:TextBox>
                </td>
                <td width="10%">
                    <asp:RequiredFieldValidator ID="txtEmailRequired" runat="server" Display="Dynamic"
                        ValidationGroup="InputValidate" ControlToValidate="txtEmail" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="txtEmailRx" runat="server" Display="Dynamic"
                        ValidationGroup="InputValidate" ControlToValidate="txtEmail" ErrorMessage="*" ForeColor="Red"
                        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
                </td>
            </tr>
            <tr>
                <td width="10%"></td>
                <td width="20%">Phone</td>
                <td width="60%">
                    <asp:TextBox ID="txtPhone" runat="server" Width="98%"></asp:TextBox>
                </td>
                <td width="10%">
                    <asp:RequiredFieldValidator ID="txtPhoneRequired" runat="server" Display="Dynamic"
                        ValidationGroup="InputValidate" ControlToValidate="txtPhone" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
                    <asp:RegularExpressionValidator ID="txtPhoneRx" runat="server" Display="Dynamic"
                        ValidationGroup="InputValidate" ControlToValidate="txtPhone" ErrorMessage="*" ForeColor="Red"
                        ValidationExpression="^[0]\d{1,2}[\s,-]\d{5,7}$"></asp:RegularExpressionValidator>
                    <!-- solve validation probs -->
                </td>
            </tr>
            <tr>
                <td width="10%"></td>
                <td width="20%">Password</td>
                <td width="60%">
                    <asp:TextBox ID="txtPassword" runat="server" Width="98%"></asp:TextBox>
                </td>
                <td width="10%">
                    <asp:RequiredFieldValidator ID="txtPasswordRequired" runat="server" Display="Dynamic"
                        ValidationGroup="InputValidate" ControlToValidate="txtPassword" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td width="10%"></td>
                <td width="20%">User Type</td>
                <td width="60%">
                    <asp:DropDownList ID="txtUserType" runat="server" Width="99.5%">
                        <asp:ListItem></asp:ListItem>
                        <asp:ListItem>Student</asp:ListItem>
                        <asp:ListItem>Lecturer</asp:ListItem>
                        <asp:ListItem>Admin</asp:ListItem>
                    </asp:DropDownList>
                </td>
                <td width="10%">
                    <asp:RequiredFieldValidator ID="txtUserTypeRequired" runat="server" Display="Dynamic"
                        ValidationGroup="InputValidate" ControlToValidate="txtUserType" ErrorMessage="*" ForeColor="Red"></asp:RequiredFieldValidator>
                </td>
            </tr>
            <tr>
                <td width="10%"></td>
                <td width="20%">Course</td>
                <td width="60%">
                    <asp:DropDownList ID="txtCourse" runat="server" Width="99.5%">
                        </asp:DropDownList>
                </td>
                <td width="10%"></td>
            </tr>
        </table>

        <table ID="tblAllValidationMsg" runat="server" width="100%" cellspacing="5">
            <tr>
                <td width="10%"></td>
                <td width="80%" align="center">
                    <asp:Label id="allValidationMsg" runat="server" height="22px" ForeColor="Red"></asp:Label>
                </td>
                <td width="10%"></td>
            </tr>
        </table>

        <table ID="tblCommandButtons" runat="server" width="100%" cellspacing="10">
            <tr>
                <td width="25%"></td>
                <td width="25%" align="right">
                    <asp:Button class="navbutton" ID="btnRegister" runat="server" causevalidation="true"
                        ValidationGroup="InputValidate" Text="Register User" OnClick="btnRegister_Click" />
                </td>
                <td width="25%" align="left">
                    <asp:Button class="navbutton" ID="btnCancel" runat="server" causevalidation="false"
                        Text="Cancel" onclick="btnCancel_Click" />
                </td>
                <td width="25x%"></td>
            </tr>
        </table>
</asp:Content>
4

1 回答 1

2

对我来说,您似乎需要使用验证组将控件与您的提交按钮联系起来。 http://weblogs.asp.net/scottgu/archive/2004/10/24/246945.aspx

或者确保所有其他不应触发验证的按钮将 CausesValidation 属性设置为 False。

于 2013-01-04T23:51:29.297 回答