验证不适用于用户输入控件

时间:2014-03-07 22:26:14

标签: c# asp.net html5 validation

我在aspx页面上使用了验证,但它不起作用且没有错误

<div class="fourm-container">                         
    <div class="single-input">
        <span>email</span>
        <input name="" type="text" runat="server" id="email" />
        <asp:RequiredFieldValidator ID="RVemail" runat="server"
            ErrorMessage="*" ControlToValidate="email" Display="Dynamic"
            ForeColor="Red" SetFocusOnError="True" 
            ValidationGroup="one"></asp:RequiredFieldValidator>
    </div>
    <div class="button-container">
        <input type="submit" id="Submit" value="login" name="submit" 
            onclick="AddCustomer" runat="server" validationgroup="one" />
    </div>

2 个答案:

答案 0 :(得分:0)

使用表单标记和结束div,我尝试了这个片段,可以看到验证正在进行。 (没有onclick)如果你看到它工作,那么onclick有一个问题。

<form id="form1" runat="server">
    <div class="fourm-container">
        <div class="single-input">
            <span>email</span>
            <input name="" type="text" runat="server" id="email" />
            <asp:RequiredFieldValidator ID="RVemail" runat="server"
                ErrorMessage="*" ControlToValidate="email" Display="Dynamic"
                ForeColor="Red" SetFocusOnError="True"
                ValidationGroup="one"></asp:RequiredFieldValidator>
        </div>
        <div class="button-container">
            <input type="submit" id="Submit" value="login" name="submit" runat="server" validationgroup="one" />
        </div>
    </div>
</form>

答案 1 :(得分:0)

您无法在ValidationGroup="one"中使用RequiredFieldValidator

试一试:

<asp:RequiredFieldValidator ID="RVemail" runat="server"
                ErrorMessage="*" ControlToValidate="email" Display="Dynamic"
                ForeColor="Red" SetFocusOnError="True">
</asp:RequiredFieldValidator>