火不要对定制的文本框的OnChange事件验证 [英] Do not fire custom validate on OnChange event of a textbox
问题描述
我使用的是自定义的验证器来验证一个文本框的内容。
每次用户离开该文本框,我的客户端脚本调用,这一点,在我的情况,有点讨厌。
我想验证的仅要执行时,上的一个按钮给用户点击按钮(这是已经发生)。
有没有办法避免被上的的OnChange
事件进行验证文本框
?
我的code是在这里:
函数isGroupNameUnique(发件人,参数){
VAR有效= TRUE; VAR令牌= $('#hdnGroupNames)VAL()分('')。;
VAR组名= $('#<%= txtGroupName.ClientID%GT;')。VAL(); $。每个(令牌功能(我){
如果(组名==这一点)
有效= FALSE;
}); args.IsValid =有效;
}
< ASP:文本框ID =txtGroupName=服务器/>< ASP:按钮的ID =btnAddGroup=服务器文本=添加的onclick =btnAddGroup_Click级=bGraySmaller的ValidationGroup =ADDGROUP/>< ASP:的CustomValidator ID =validatorGroupNameAlreadyExists=服务器的ControlToValidate =txtGroupName的ErrorMessage =组名必须是唯一的ValidationGroup =ADDGROUPClientValidationFunction =isGroupNameUnique/>
上的的CustomValidator (什么就是这个属性是不是强制的唯一验证)。设置文本框相同的ValidationGroup。
< ASP:文本框ID =txtGroupName的ValidationGroup =ADDGROUP=服务器/>
< ASP:的CustomValidator ID =validatorGroupNameAlreadyExists=服务器的ErrorMessage =组名必须是唯一的ValidationGroup =ADDGROUPClientValidationFunction =isGroupNameUnique/>
I am using a custom validator to validate a textbox content. Everytime the user leaves this textbox, my client script is called, which is, in my case, a little bit annoying.
I want the validation only to be performed when the user clicks on a button given button (which is already happening).
Is there any way to avoid the validation to be performed on the OnChange
event of the TextBox
?
My code is here:
function isGroupNameUnique(sender, args) {
var valid = true;
var tokens = $('#hdnGroupNames').val().split(',');
var groupName = $('#<%= txtGroupName.ClientID %>').val();
$.each(tokens, function (i) {
if (groupName == this)
valid = false;
});
args.IsValid = valid;
}
<asp:TextBox ID="txtGroupName" runat="server" />
<asp:Button ID="btnAddGroup" runat="server" Text = "Add" onclick="btnAddGroup_Click" class="bGraySmaller" ValidationGroup="AddGroup"/>
<asp:CustomValidator ID="validatorGroupNameAlreadyExists" runat="server" ControlToValidate="txtGroupName" ErrorMessage="The Group Name has to be unique" ValidationGroup="AddGroup" ClientValidationFunction="isGroupNameUnique" />
Remove the ControlToValidate property on the CustomValidator(what is the only Validator where this property is not mandatory). Set the same ValidationGroup on the TextBox.
<asp:TextBox ID="txtGroupName" ValidationGroup="AddGroup" runat="server" />
<asp:CustomValidator ID="validatorGroupNameAlreadyExists" runat="server" ErrorMessage="The Group Name has to be unique" ValidationGroup="AddGroup" ClientValidationFunction="isGroupNameUnique" />
这篇关于火不要对定制的文本框的OnChange事件验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!