<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="NewWeb.Pages.Admin.Product.WebForm1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script type="text/javascript" src="/Content/JScript/Jquery/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="/Content/JScript/Jquery/jquery.validate.js"></script>
<script type="text/javascript">
$(function() {
$("#form1").validate({
rules: {
formView_txtTitle: {
required: true
}, txtTitle: {
required: true
}
},
messages: {
formView_txtTitle: {
required: "need!"
},
txtTitle: {
required:"Nedd!"
}
},
submitHandler: function(form) {
alert("KO");
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="formView" runat="server" DefaultMode="Insert">
<InsertItemTemplate>
<asp:TextBox ID="txtTitle" runat="server"></asp:TextBox>
</InsertItemTemplate>
</asp:FormView>
<asp:TextBox ID="txtTitle" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="提交" onclick="btnSubmit_Click" />
</div>
</form>
</body>
</html>
<div>
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBALK9+7hCQLFlpLaBAL55JyzBALCi9reA5ezSWV8BbIAiF3Q4K433+d2dU9E" />
</div>
<div>
<table cellspacing="0" border="0" id="formView" style="border-collapse:collapse;">
<tr>
<td colspan="2">
<input name="formView$txtTitle" type="text" id="formView_txtTitle" />
</td>
</tr>
</table>
<input name="txtTitle" type="text" id="txtTitle" />
<input type="submit" name="btnSubmit" value="提交" id="btnSubmit" />
</div>
</form>
为什么可以验证ID为txtTitle的控件,却不能验证ID为formView_txtTitle的控件?
是根据表单元素的name,而不是ID