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

Posted on 2014-08-09
Last Modified: 2014-08-23

I have an 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?

Question by:jxbma
    1 Comment
    LVL 14

    Accepted 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

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction Got endorsements from your clients?  Great!  There is almost nothing better than word-of-mouth advertising.  But how can you do that on the internet?  Sure you can make a page for endorsement quotations and list them all, but who is …
    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now