PopupControlExtender bug?

Last post 12-06-2006 2:26 PM by gpbenoit. 3 replies.

Sort Posts:

  • PopupControlExtender bug?

    05-17-2006, 2:27 PM
    • Member
      110 point Member
    • shines2k
    • Member since 03-29-2006, 10:51 PM
    • Posts 22

    I'm having problems with dismissing a control that is being popped up by the PopupControlExtender.

    The control in question is a panel with a listbox in it. When the panel first pops up, if I click outside the panel the popup is dimissed, just like it should be. But if I click on an item in the listbox while the panel is popped up (giving it focus), I have to click twice outside of the panel to dismiss the popup.

    I found this code in the PopupControlExtender: 

        this._onClick = function() {
            // Handle clicks in the popup We use a simple flag because
            // cancelling the event bubbling doesn't always seem to work
            // in IE as we expect.  We then check in _onBodyClick whether
            // it was set to ignore the event.
            _wasClicked = true;
            event.cancelBubble = true;
        }
    

    My understanding of this is that the _wasClicked flag is set because this is a click in our control, and we don't want the onBodyClick() handler to think it's a click outside the control; the flag is set so that onBodyClick() eats the click. You do this because cancelling the event bubbling doesn't work predictably, that is, you try to cancel the bubbling in onClick(), but sometimes onBodyClick() gets called anyway. Therefore, if onBodyClick(), sees _wasClicked = true, it eats the event and resets _wasClicked:

        this._onBodyClick = function() {
            // Handle clicks for the whole window
            if (_wasClicked) {
                // If we received a click that we expected, do nothing
                _wasClicked = false;
            } else if (_popupVisible) {
                // If the click was outside our control, hide the popup
                this.hidePopup();
            }
        }
    

    Now, the problem I'm having with the extender is that two clicks outside the panel are required to dismiss the popup if the popup is given focus with a click. My suspicion was that the first click was being eaten through the _wasClicked path, and the second was dismissing the popup.

    So somehow _wasClicked was being set in a control event handler, but not being reset by onBodyClick(). I figured that this could happen if "event.cancelBubble = true" was actually doing what it was supposed to. That is, if _wasClicked is set to true on the assumption that onBodyClick() will be called, yet event.cancelBubble = true works and never triggers onBodyClick(), then _wasClicked will not be reset, and will be "true" even if I click outside the control, thus eating that click and not dismissing the popup.

    When I commented out the line "event.cancelBubble = true", I seem to have fixed the problem: the popup always disappears after a single click outside of the control.

    My question is whether I really "fixed" this, as there may be some behavior that I'm not aware of or some good reason why event.cancelBubble must be set to true.

  • Re: PopupControlExtender bug?

    05-18-2006, 2:03 PM
    • Contributor
      4,198 point Contributor
    • Ted Glaza [MSFT]
    • Member since 04-12-2006, 11:51 PM
    • Microsoft
    • Posts 847
    • AspNetTeam

    Hi shines2k,

    Thanks for spotting this one.  You're right about how we use _wasClicked to work around event bubbling not being perfect.  I think that if you take out the event.cancelBubble it starts to have issues on Safari.  I'm going to investigate it further and try to find a better solution.

    Thanks,
    Ted

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: PopupControlExtender bug?

    07-31-2006, 10:28 AM
    • Member
      367 point Member
    • andymarks
    • Member since 05-22-2006, 2:32 PM
    • England
    • Posts 83

    Is there a resolution to this bug?  I have the same problem.

     

    Andy.

  • Re: PopupControlExtender bug?

    12-06-2006, 2:26 PM
    • Member
      328 point Member
    • gpbenoit
    • Member since 10-19-2006, 10:13 AM
    • Atlanta, GA
    • Posts 98

    I am bumping this b/c I am having the exact same problem and am wondering if I should comment out the line event.cancelBubble = true like shines2k did...or if there is a better fix??

    If I comment out the line that Shines2k did, then will it still work in Safari (That was Ted Glaza's worry).

    Thanks,

    Greg

Page 1 of 1 (4 items)