[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 630
  • Last Modified:

How can I hide a ModalPopupExtender embedded in an ASCX user control through javascript (with no postback)?


I have an Asp.net application.
Within that application I have a ModalPopupExtender embedded within an ASCX user control.
I would like to be able to wire up a cancel button so I can hide the popup when user presses cancel
without doing a post back.

Here is what I have so far:
<cc1:ModalPopupExtender ID="PopupExtender1" runat="server" PopupControlID="pnlPopup" BehaviorID="mdlPopupForm"
    TargetControlID="btnHiddenSubmit" OkControlID="btnOkay" CancelControlID="btnCancel" 
    Drag="true" PopupDragHandleControlID="PopupHeader" EnableViewState="true" 
    BackgroundCssClass="modalBackground" ClientIDMode="Static" />

Open in new window

Here is the HTML for btnCancel:
<input type="button" id="btnCancel" onclick="cancelPopupPanelClick()" value="Cancel" />

Open in new window

Here is the javascript:
    function cancelPopupPanelClick() {

        var modalPopup = $find('PopupExtender1');
        if (modalPopup != null) {

Open in new window

The event fires fine. The issue I'm having is that I can't "Find" the modalPopup in order to hide it.
Is this complicated by the fact that I have the ModalPopupExtender embedded in an ASCX control?

I have verified that the "AjaxControlToolkit.ToolkitScriptManager" is loaded in the containing ASPX page.

Can someone get me pointed in the right direction?

1 Solution
use Behaviour ID of your modalpopup...

change this  
var modalPopup = $find('PopupExtender1');

Open in new window

var modalPopup = $find('mdlPopupForm');

Open in new window


Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now