我一直试图让验证我的文本框和唯一可行的事情是设置工作验证文本框时,另一个文本框包含文本
autoPostBack=true
,并在回发textbox_change事件添加
textBox3.Validator.Enabled = true;
但我注意到,chrome和边缘dosent总是触发回发事件,然后验证从未激活。对于像添加验证这样的小事情做回发并不方便用户使用。它必须是一个更简单的方法..
所以我得到这个
<asp:TextBox runat="server" ID="txt1"/> <--- Dont need validation on that one, when starting to type values are populated from a ajax call
<asp:TextBox runat="server" ID="txt2"/> <--- Here i want to add validation when txt1 contains something, no validation should fire if the user steps in on txt1 and then out without writing text
<asp:RequiredFieldValidator ID="txt2Validator" runat="server" Enabled="false" ErrorMessage="" Display="Static" SetFocusOnError="True" ValidationGroup="valgroup1" ControlToValidate="txt2"/>
<asp:DropDownList ID="ddl1" runat="server" /> <--- also validate this only when txt1 contains text
<asp:RequiredFieldValidator ID="ddl1Validator" runat="server" Enabled="false" ErrorMessage="" Display="Static" SetFocusOnError="True" ValidationGroup="valgroup1" ControlToValidate="ddl1"/>
那么,有没有在jQuery的办法所需的字段验证设置为Enabled =当txt1中包含的文字可能有真正的onblur事件?
部分解决
行,所以我是有点快,不要以为我自己...... 我挣扎了一整天找我的Ajax请求的错误和时得到固定,我是做出来的思考果汁,只是放弃了,问了这个问题。但是,由于知道这个肩膀是一个问题,我尝试了编码,结果与此。有用!是! 我唯一不会做的事情是,如果我可以让它只在txt1包含文本时添加验证,现在验证启用为儿子,因为我在txt1中点击,然后再次出来。有没有,如果this.txt1.contains.text那么事情与jQuery?
<script type=text/javascript>
$(document).ready(function() {
$("#<%= txt1.ClientID %>").blur(function() {
ValidatorEnable(document.getElementById('<%=txt2Validator.ClientID%>'), true);
ValidatorEnable(document.getElementById('<%=ddl1Validator.ClientID%>'), true);
});
});
</script>