我有一个包含所有这些字段的表单,并且它们都附加了必需的验证器。
我的目标是让用户输入表单,如果他填写姓氏并点击提交,表单仍将回发以保存姓氏,但其他 3 个字段将显示一条错误消息,显示“blah blah blah”
基本上我需要验证表单,但即使表单失败,我也只想显示错误摘要,但仍提交有效字段(如果有)。
<input runat="server" id="LastName" type="text" name="LastName"/>
<asp:RequiredFieldValidator ID="rvLastName" runat="server" ErrorMessage="Please type last name" ControlToValidate="LastName">Last Name Required</asp:RequiredFieldValidator>
<input runat="server" id="FirstName" type="text" name="FirstName"/>
<required first Name>
<input runat="server" id="MiddleName" type="text" name="MiddleName"/>
<required middle name>
<input runat="server" id="EmailAddress" type="text" name="EmailAddress"/>
<required emailaddress>
<script type="text/javascript">
$(document).ready(function () {
$('#forminfo').validate({
rules: {
LastName: {
required: true
},
EmailAddress: {
required: true,
email: true
}
},
messages: {
LastName: "Please enter your last name",
EmailAddress: "Please enter a valid email address"
}
});
});
</script>