开发者

jQuery & ASP.NET validators conflict problem

开发者 https://www.devze.com 2023-03-29 10:51 出处:网络
I have a page which has a form with a few validators. I also have a button (HTML submit) which resets form and clears all textboxes. The code works fine the first time I click the button, which clears

I have a page which has a form with a few validators. I also have a button (HTML submit) which resets form and clears all textboxes. The code works fine the first time I click the button, which clears the form. But if I refill the form and try to clear the form for the second time, it won't work. I also have other jQueries to toggle areas of code, they also stop working after this.

One thing to mention is that when I press clear form button, asp validators show themselves, which is odd to me because I have not put a validation开发者_JS百科Group on them and not on my button. I think this happens because the button tries to do a postback.

So two questions, first what's causing my queries not to work?

And second, how do I stop the button from attempting to post back (which causes validators to be shown)?

The code looks something like this:

<script>
  scripts clearing the form and doing toggle actions here.
</script>
<form>
  label & texbox pairs to get info from user, accompanied by Required field validators.
  <asp:Button ... The Button to submit form />
  <input typ="submit" value="Clear Form" /> -->The button to clear form on client side.
</form>


This will stop the submit -- add a return false.

 $('#btnResetForm').click(function () {
            $('#<%=txtFname.ClientID %>' +
            ',#<%=txtLname.ClientID %>' +
            ',#<%=txtNatNo.ClientID %>' +
            ',#<%=txtBirthCertNo.ClientID %>' +
            ',#<%=txtUsername.ClientID %>' +
            ',#<%=txtCellNo.ClientID %>' +
            ',#<%=txtPhoneNo.ClientID %>'
            ).val("");
            return false;
        });

You might want to use toggle() and not show and hide to let buttons keep working.

0

精彩评论

暂无评论...
验证码 换一张
取 消