5

I am trying to show an asp:ModalPopupExtender using jQuery, without any success. Here is what I have :

ASP.NET

<asp:ModalPopupExtender BehaviorID="confirmPopup" ID="confirmPopup" runat="server" />

JAVASCRIPT

function ShowConfirmPopup() {
    var _id = '#<%= confirmPopup.ClientID %>';
    var modal = $find(_id);
    modal.show();
}

What happens is that modal is always equal to null, so the popup never gets shown. What am I doing wrong?

Jean-François Beaulieu
  • 4,305
  • 22
  • 74
  • 107

1 Answers1

6

$find() is not part of jQuery, but of ASP.NET AJAX. Therefore, you should not prefix the behavior id with a hash sign:

function ShowConfirmPopup()
{
    var modal = $find("confirmPopup");
    modal.show();
}
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • I didn't know that, but still, even without the hash sign, it doesn't find the control – Jean-François Beaulieu May 26 '11 at 18:53
  • @JFB, that's probably because the `ClientID` of your control is not the same as its behavior id in your case. Since you explicitly specify a behavior id in your markup, it also makes sense to hard-code it in the client-side code. Answer updated accordingly. – Frédéric Hamidi May 26 '11 at 18:56
  • édéric, OK! Since I am using MasterPages, the `ClientID` gets altered, so it's better to use `BehaviorID` like this: `var _id = '<%= confirmPopup.BehaviorID %>';` – Jean-François Beaulieu May 26 '11 at 20:35