首页 新闻 会员 周边 捐助

jquery.validate不能捕获数据源里面的控件

1
悬赏园豆:20 [已解决问题] 解决于 2011-04-02 17:10
<%@ 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的控件?

FelixLoeng的主页 FelixLoeng | 菜鸟二级 | 园豆:244
提问于:2011-04-02 14:39
< >
分享
最佳答案
0

是根据表单元素的name,而不是ID

收获园豆:20
xxwgcg | 菜鸟二级 |园豆:243 | 2011-04-02 15:50
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册