GeoffWilson
GeoffWilson

Reputation: 433

Opening ModalPopupExtender Using JavaScript

I have a Popup in my aspx page that i want to open based on criteria that has to be met by javascript. The problem i am having is that i cannot seem to get the modalpopupextender to work no matter what i try.

I have tried using PageMethods, _doPostBack() and $Find(PopupClientId).Show();

None of the above seem to work and i cannot figure out why.

This is my JavaScript.

    function RequotePopup(popup, status) {
        if (status = true) {
            var thePopup = document.getElementById(popup);
            thePopup.style.visibility = "visible";
        } else {
            alert("Please select a record for Re-Quote");
        }
    }
    function checkGridView() {
        var hdnCheckboxIDs = document.getElementById("ctl00_ContentPlaceHolder1_hdnCheckboxID");
        var arrCheckboxIDs = hdnCheckboxIDs.value.split(",");
        var checked = false;


        for (var i = 0; i < arrCheckboxIDs.length; i++) {
            if (arrCheckboxIDs[i] != "") {
                var ckbItem = document.getElementById(arrCheckboxIDs[i]);
                if (ckbItem != null) {
                    if (ckbItem.checked == true) {
                        checked = true;
                    }
                }
            }
        }
        if (checked == true) {
            //var modal = $find('<%= ReQuoteBtn_ModalPopupExtender.ClientID %>');
            //modal.show();
            PageMethods.ShowExtender();
            ShowPopup('RequotePopup');
        } else {
            alert("Please select a record for Re-Quote");
        }
    }

And This is my ASP.Net.

<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />

<asp:Button ID="ReQuoteBtn" runat="server" Text="Re-Quote" OnClientClick="Javascript:checkGridView()"
    CssClass="Sales" />
<asp:ModalPopupExtender ID="ReQuoteBtn_ModalPopupExtender" runat="server" DynamicServicePath=""
    BackgroundCssClass="modalBackground" Enabled="True" BehaviorID="RequoteModal" PopupControlID="RequotePopup"
    TargetControlID="ReQuoteBtn" OnCancelScript="cmdCancelrq">
</asp:ModalPopupExtender>

Upvotes: 1

Views: 9838

Answers (1)

Alice
Alice

Reputation: 1265

I'm not sure if you have tried this, but it should work if you find the ModalPopupExtender by BehaviorID.

As your BehaviorID is RequoteModal, let try this sample:

To show the popup

$find('RequoteModal').show();

To hide the popup

$find('RequoteModal').hide();

Edit:

I just noticed that you set Enabled="False" for the ModalPopupExtender, this will not allow the modal to call show() method, you may got error message such "Unable to get property 'show' of undefined or null reference".

Please remove that setting and try again.

Upvotes: 3

Related Questions