asp:RegularExpressionValidator禁用按钮

时间:2018-10-25 17:37:11

标签: asp.net regex validation webforms

我在触发asp:RegularExpressionValidator时遇到问题。它会禁用asp.net按钮,即使用户修复了电子邮件,也不会使其成为有效表单?     

<dd class="lblDemo ddDemo">
    <asp:CustomValidator ID="txtbxIDValidator" runat="server" OnServerValidate="txtbxNameAndId_Validate" Display="Dynamic"
        ForeColor="Red"></asp:CustomValidator>
</dd>
<dd class="lblDemo ddDemo">
    <asp:CustomValidator ID="txtbxEmailRequiredValidator" runat="server" OnServerValidate="txtbxEmailRequired_Validate"
        Display="Dynamic" ForeColor="Red"></asp:CustomValidator>
    <asp:RegularExpressionValidator ID="txtEmailFormatValidator" ErrorMessage="Please give a valid Email Address" runat="server"
        ControlToValidate="txtbxEmail" SetFocusOnError="True" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
        ForeColor="red" Display="Dynamic" />
    <asp:CustomValidator ID="txtbxEmailDomainValidator" runat="server" OnServerValidate="txtbxEmailDomain_Validate"
        Display="Dynamic" ForeColor="Red"></asp:CustomValidator>
</dd>
</dl>
<p style="text-align: center">
    <%--<asp:Button ID="btnPrevious1" class="btnDemoNext" runat="server" CausesValidation="true" OnClick="btnPrevious_Click" OnClientClick="this.disabled=true" Visible="False" />--%>
    <asp:Button ID="btnNext2" runat="server" CausesValidation="true" class="btnDemoNext" OnClick="btnNext_Click"
        OnClientClick="this.disabled=true" />
</p>

1 个答案:

答案 0 :(得分:2)

您需要从按钮定义中删除以下代码。

OnClientClick="this.disabled=true"

您可以添加带有按钮和正则表达式验证器的验证组。要了解更多如何使用验证组,您可以按照以下文章进行操作 Validation Group In Asp.Net Validation Group in Asp.Net