【发布时间】:2012-03-21 11:35:07
【问题描述】:
我在使用 JavaScript 和 jQuery 进行客户端验证时遇到了很多麻烦。
我在一个页面 (.aspx) 上有 2 个用户控件 (.ascx),每个控件都有自己的按钮,定义如下
Page
user control 1
textbox 1
textbox 2
Button 1
user control 2
textbox 3
textbox 4
Button 2
按钮 1 和按钮 2 具有相同的 CSS 类。 我还有一个页面引用的 JavaScript 脚本。
使用 jQuery 我可以准确地选择按钮并将点击事件绑定到它们,如下所示:
$('.buttonCssClass').click(function() {
// If the user control fields are not valid then do nothing
if (typeof (Page_IsValid) == 'undefined' || Page_IsValid) {
return false;
}
// If the user control fields are valid then
// disable the button and replace the CSS class and add an image (progress spindle)
// until the processing is over - this is to prevent the user from clicking multiple
// times for long running and async processes.
});
当我单击按钮 1 时,我只想检查该用户控件中的字段的有效性 - 而不是页面中的所有字段。现在,页面上所有控件中的所有字段都经过有效性检查 - 这意味着我的 JavaScript 函数总是返回 false。
有人可以帮我解决这个问题吗?
【问题讨论】:
-
@Tim - 感谢您的编辑。只有我在这个网站上的第二个问题。
标签: javascript jquery asp.net validation