将 jquery 与嵌套母版页结合使用
谁能告诉我如何在 ASP.NET 嵌套母版页中使用 jquery。我有我的主主页,其中添加了 jquery libaray 的链接以及验证框架。然后,我创建了另一个带有一些样式的母版页,并基于该母版页创建了一个 aspx 页面。
如何将验证框架附加到页面内的文本框?
我已经尝试过
$("#aspnetForm").validate({
rules: {
<%=txtPostCode.UniqueID %>: {
minlength: 2,
required: true
},
<%=txtContactEmail.UniqueID %>: {
required: true,
email:true
}
}, messages: {
<%=txtPostCode.UniqueID %>:{
required: "* Required Field *",
minlength: "* Please enter atleast 2 characters *"
}
}
});
但是没有任何反应。有人能指出我正确的方向吗?
Can anyone show me how to use jquery in an asp.net nested masterpage. I have my main masterpage where I have added the link to the jquery libaray and also the validation framework. I have then created another masterpage with some styling and created a aspx page based on that masterpage.
How can I attach the validation framework to textboxes within my page?
I have tried
$("#aspnetForm").validate({
rules: {
<%=txtPostCode.UniqueID %>: {
minlength: 2,
required: true
},
<%=txtContactEmail.UniqueID %>: {
required: true,
email:true
}
}, messages: {
<%=txtPostCode.UniqueID %>:{
required: "* Required Field *",
minlength: "* Please enter atleast 2 characters *"
}
}
});
However nothing happens. Can anyone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以编写将 ID 传递给 jQuery 函数的包装器方法,并使用
RegisterStartupScript
或子页面上的内联 JS 调用这些方法:Javascript:
.aspx:
其中
GetClientSelector
返回字符串,它是一个选择器,要么只是一个 ID,要么可能是一些服务器派生的类集。或者其他什么,真的。You can write wrapper methods that pass IDs to jQuery functions, and call those methods either with
RegisterStartupScript
or inline JS on the child pages:Javascript:
.aspx:
where
GetClientSelector
returns a string that's a selector, either just an ID or potentially some server-derived set of classes. Or anything else, really.因为 ASP.NET 会破坏 ID,所以最好的选择可能是为服务器控件设置 CSS 类并以这种方式访问它们:
这不是最有效的 JS,因为您是按类而不是 ID 进行选择,但它会节省您的时间尝试处理 WebForms 中的 ASP.NET 损坏的 ID 是一个令人头疼的问题。
Because ASP.NET mangles the ID's, your best bet may be to just set CSS classes for your server controls and access them that way:
It's not the most efficient JS because you're selecting by classes instead of IDs, but it will save you headaches down the road from trying to deal with ASP.NET mangled IDs in WebForms.