admin管理员组文章数量:1278912
I have TextBox with RequiredFieldValidator on my page. I also have link that calls some simple javascript.
<asp:TextBox ID="TextBox1" runat="server" />
<asp:RequiredFieldValidator
ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" />
<asp:LinkButton ID="Link1" runat="server" OnClientClick="DoSomething(); return false;" CausesValidation="false"Text="Do" />
function DoSomething() {
textbox1.val("blah"); }
When user type something into textbox and then delete that text and focus next control - then validator fires. Then user can use link that adds text using javascript. TextBox1 text is no longer empty but RequiredFieldValidator still shows error message. How to prevent that?
I have TextBox with RequiredFieldValidator on my page. I also have link that calls some simple javascript.
<asp:TextBox ID="TextBox1" runat="server" />
<asp:RequiredFieldValidator
ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBox1"
Display="Dynamic" />
<asp:LinkButton ID="Link1" runat="server" OnClientClick="DoSomething(); return false;" CausesValidation="false"Text="Do" />
function DoSomething() {
textbox1.val("blah"); }
When user type something into textbox and then delete that text and focus next control - then validator fires. Then user can use link that adds text using javascript. TextBox1 text is no longer empty but RequiredFieldValidator still shows error message. How to prevent that?
Share Improve this question edited Jul 2, 2011 at 19:02 Muhammad Akhtar 52.2k37 gold badges139 silver badges191 bronze badges asked Apr 22, 2010 at 8:47 jlpjlp 10.4k16 gold badges56 silver badges75 bronze badges3 Answers
Reset to default 6you can use javascript ValidatorEnable
function
ValidatorEnable(document.getElementById('<%= ValidatorID.ClientID %>'), true);
I would remend a CustomValidator
here since you do NOT want the normal RequiredFieldValidator
behavior. The CustomValidator
client method will only run on postback.
The whole point of the validators is that they are to be used for both server side and client side validation.
If you only want to validate on the server side, don't use a validator and simply check that the values are valid and report an error.
本文标签: javascriptHow disable RequiredFieldValidator in scriptStack Overflow
版权声明:本文标题:javascript - How disable RequiredFieldValidator in script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741255658a2366623.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论