views:

24

answers:

1

Hi,

I have a page with 2 user controls on it, UC1 and UC2.

Both user controls poll the database via an ajax call.

UC1 is to poll IF UC2's button has not been pressed.

i.e. only 1 ajax poll at a time, given the above logic.

Both UC's have an jquery onReady call that initializes the timer.

How can I tell UC1 not to poll IF UC2's button has been pressed?

+2  A: 

You could add a class attribute to UC2 on the click or submit event, and have UC1 check for the existence of that class. If it is in place, don't trigger the event.

$("uc2").click(function() {
    if (!$(this).hasClass("pressed")) {
        $(this).addClass("pressed");
    }
});

$("uc1").click(function() {
    if ($("uc2").hasClass("pressed")) {
        return false;
    } else {
        // whatever
    }
});

Edit: Re-read and to clarify... if UC1 is polling automatically with a timer, you can check for the class during that event. Doesn't necessarily have to exist in a click handler.

Mark Hurd