Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1022
  • Last Modified:

jquery causing extra TextChanged events

I have a form that has 3 text boxes that are masked using the jquery input mask plugin.  All 3 textboxes have a TextChanged event and AutoPostBack=true;
The problem is that when I change the text of one textbox and hit enter, it is firing the TextChanged event for all 3 boxes.

I assume that it is due to how jquery does the masking, and that it changes the text at a point late enough in the event cycle that .net registers it as being changed.  Is there a way to prevent it?  I have tried using return false at the end of my jquery function, but it's not helping either.

Here is the relevant jquery code, at the top of my aspx page:

            $("#<%= txtPrimaryPhone.ClientID %>").mask("999-999-9999? x9999");
            $("#<%= txtOtherPhone.ClientID %>").mask("999-999-9999? x9999");
            $("#<%= txtZip.ClientID %>").mask("99999?-9999");
            return false;

Open in new window

1 Solution
You perform the masking for all the 3 text boxes in single function and calling that function if first text box is it?
AlliedAdminAuthor Commented:
I'm not really sure what you mean, but that function will mask all 3 of my inputs, which are 2 phone numbers and a zip code.

Each of those text boxes has an OnTextChanged event (server side event) that is fired when the text is changed.  However, the OnTextChanged event is firing for all 3, even if I only change one text box.  For example, if the page loads up, and I change the zip code from 12345 to 54321 and hit enter, it is firing the OnTextChanged event for all 3 inputs, even though only one actually changed.
Use jQuery document ready:

$(document).ready(function() {
   // put all your jQuery goodness in here.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now