如何使用javascript从IFrame中的子项启用/禁用父模式弹出窗口上的按钮

时间:2014-07-22 02:05:28

标签: javascript jquery asp.net

我正在尝试从子窗口禁用/启用父窗口的按钮。

以下是父页面的摘录。

<ajaxToolkit:ModalPopupExtender ID="mpeTest" runat="server" 
  CancelControlID="btnClose" PopupControlID="pnl1" TargetControlID="showMpe"/>

<asp:Panel ID="pnl1" runat="server" >
           <ContentTemplate>
                <iframe id="ContentIframe" runat="server">
                        <p>Your browser does not support iframes.</p>
                </iframe>
            </ContentTemplate>
    <p class="submitButton">
        <asp:Button ID="btnClose" runat="server" Text="Close" />
        &nbsp;
        <asp:Button ID="btnTest" runat="server" Text="EnableDisable" />
    </p>
</asp:Panel>

在iframe中加载的子页面中,我有一个带有LinkBut​​tons的网格视图。我试图让其中一个LinkBut​​tons从父窗口禁用/启用btnTest。

我尝试了很多东西,但我似乎无法解决这个问题...... 例如:

<script type="text/javascript" >
    $(document).ready(function() {
        jQuery('[id$="linkButtonDisable"]').click(function() {
           window.parent.opener.document.getElementById("btnTest").disabled = true;
        });
    });
</script>

任何人都可以帮助我。我对这个很新了

1 个答案:

答案 0 :(得分:0)

也许你应该尝试这样的事情......

$("#<%=linkButtonDisable.ClientID %>").click(function() {

       //Option N#1 HTML Attribute 
       $("#<%=btnTest.ClientID %>").attr("disabled","disabled");

       //Option 2 With jQueryMobile integration, the same it supposed to work if your using bootstrap, but I ignore the css class for disabling an element
       $("#<%=btnTest.ClientID %>").addClass("ui-disabled");

       //Also if you want to toggle states between disable/enable maybe this could work either...
       var id = $("#<%=btnTest.ClientID %>"); 
       var state = id.attr("disabled");
       //Dunno if it's needed to catch if disabled attr it isn't set
       if(state == "disabled") {
           id.removeAttr("disabled");
       } else {
           id.attr("disabled","disabled");
       }

});

希望这有帮助!...