jquery causing extra TextChanged events

Posted on 2011-04-25
Last Modified: 2012-05-11
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

Question by:AlliedAdmin
    LVL 9

    Expert Comment

    You perform the masking for all the 3 text boxes in single function and calling that function if first text box is it?

    Author Comment

    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.
    LVL 6

    Accepted Solution

    Use jQuery document ready:

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now