ASP.NET验证:如何在控制验证失败的同时显示验证错误消息和`*`?

时间:2016-02-16 16:39:23

标签: jquery asp.net asp.net-validators

我正在验证该表单并使用jQuery对话框显示错误。

这是一个jQuery代码,在弹出窗口中显示错误摘要:

function WebForm_OnSubmit() {
    if (typeof (ValidatorOnSubmit) == "function" && ValidatorOnSubmit() == false) {
        $("#errorDisplay").dialog({
            title: "Validation Error",
            modal: true,
            resizable: false,
            width: 250,
            buttons: {
                Close: function () {
                    $(this).dialog('close');
                }
            }
        });
        return false;
    }
    return true;
}

这是我定义控件:

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtAddName" Display="None" ErrorMessage="Name is Required" ForeColor="Red"></asp:RequiredFieldValidator>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtAddEmail" Display="None" ValidationExpression="^[^@]+@[^@]+\.[^@]+$" ErrorMessage="Invalid Email Address" ForeColor="Red"></asp:RegularExpressionValidator>

这是validation summary

    

是否可以更改我的验证,因此,我显示失败控件的*并仍显示弹出的错误消息?

1 个答案:

答案 0 :(得分:0)

我想我明白了。 我需要更改.input-link { color: blue; text-decoration: underline; cursor: pointer; } .input-link:hover, .input-link:focus { color: red; } p { height: 100vh; }并将<label class="input-link" for="email">Sign up</label> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Vitae dolorum atque, eaque, modi ducimus commodi iure officia reprehenderit eius quasi eligendi natus aliquam dolore recusandae nobis. Perferendis inventore ea quisquam.</p> <div id="bottom"> <input type="email" name="email" id="email" placeholder="email address"> </div>放在两个控件的标记之间

就像那样:

Display=static