最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net - Opening ModalPopupExtender Using JavaScript - Stack Overflow

programmeradmin0浏览0评论

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>

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>
Share Improve this question edited Feb 19, 2014 at 9:39 GeoffWilson asked Feb 18, 2014 at 9:44 GeoffWilsonGeoffWilson 4337 silver badges21 bronze badges 2
  • Have you checked the reference to the AjaxControlToolkit and maybe remove/re-add it yet, just to be sure? – Wim Ombelets Commented Feb 18, 2014 at 9:51
  • I know that the AjaxControlToolkit works because it is being used on the majority of pages in the website. – GeoffWilson Commented Feb 18, 2014 at 10:18
Add a ment  | 

1 Answer 1

Reset to default 3

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.

发布评论

评论列表(0)

  1. 暂无评论