Search code examples
jqueryasp.netajaxcontroltoolkit

jQuery .click() and ModalPopupExtender


On my ASP.NET Web Forms page, there is a Panel which is a modal popup (using ModalPopupExtender in the AJAX Control Toolkit). Apparently, the jQuery .click(f) method does not work if the target control is in a popup. The following code works only if I move the CheckBox out of the popup:

$("#checkBox").click(function() {
  // do something
});

This is how the checkbox is declared on the server site:

<asp:CheckBox runat="server" ID="checkBox" Text="..." ClientIDMode="Static" />

I need to bind a handler to the checkbox, while in the panel. Does anybody habe a hint for me?

Matthias


Solution

  • I don't know how the popups are implemented within the AJAX Control toolkit, but I suspect that the controls are added to the popup dynamically. If that is the case, you should do this (assuming you're not using an outdated version of jQuery):

    $("#checkBox").live('click', function() {
      // do something
    });
    

    (See here to understand how this works.)

    Try that and see if it works. If you're stuck with an old version of jQuery, I recommend using the LiveQuery plugin.