2013-01-04 42 views
0

好的,这仍然造成问题两天后.. 我有一个asp.net表单组成的几个文本字段和一个下拉列表和一个注册按钮。asp.net验证控件禁止按钮单击事件

问题: 当我申请的客户端验证的文本字段和下拉,按钮点击事件被抑制(用于网页上的所有按钮,不只是提交按钮也为全球导航按钮从母版继承)。某些字段有多个验证器(例如,必填字段和注册表项)。

当我将任何验证器注释掉时,所有按钮的单击事件都按预期工作。

我似乎是一个疯狂的工作,插入一个额外的不需要的'虚拟'验证器只是为了评论,但它似乎只与n-1验证器一起工作(即无论我在页面上有多少验证器,只与其中任何一个人注释掉)。

在网络上有一篇关于aspalliance.com上关于这个确切主题的文章,但遗憾的是,链接被打破。任何人都可以请建议一个解决方案?

谢谢,Daf。

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

<%@ 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> 

回答

2

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

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

+0

@Sebastian ..感谢您的回复。我根据您的建议实施了验证组。虽然页面上的所有其他按钮现在都到达并执行后面的代码,但注册按钮仍然可以成功触发验证,但不会隐藏代码。更改按钮上的CausesValidation属性似乎不会影响这个.. –

+1

那么,如果客户端验证踢入页面将不会回发,因此服务器端处理程序将不会执行,对吧?或者我错过了什么? –

+0

这就是我最初的想法。如果是这种情况,为什么当任何一个验证器被注释掉时留下几个其他的“活动”验证器都可以正常工作?顺便说一句,我是相当新的asp.net,所以它可能更有可能我失去了一些东西.. –